久しぶりに、WebAPIテンプレートを使ってみたら、デフォルトがuse-minimal-apisになっていて、コードが以下のようにProgram.csに全て入っているコードが生成されてビックリした。
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
app.MapGet("/weatherforecast", () =>
{
・・・
})
.WithName("GetWeatherForecast")
.WithOpenApi();
app.Run();今まで通り、Controllerを使用するには、下記のように、dotnet newにオプションを指定する必要があるようだ。
dotnet new webapi -o <プロジェクト名> --use-controllers
#または
dotnet new webapi -o <プロジェクト名> -controllersvar builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();デフォルトでこちらにして欲しいんだけど・・・
何かminimal apiだと、Node.jsみたいだし、Program.csにコードを全て書くのは好きじゃないなぁ。






Users Today : 39
Users Yesterday : 44
Users Last 7 days : 182
Users Last 30 days : 963
Users This Month : 842
Users This Year : 15668
Total Users : 93472
Views Today : 50
Views Yesterday : 53
Views Last 7 days : 232
Views Last 30 days : 1223
Views This Month : 1050
Views This Year : 21255
Total views : 131190
Who's Online : 0