久しぶりに、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 : 0
Users Yesterday : 47
Users Last 7 days : 276
Users Last 30 days : 901
Users This Month : 573
Users This Year : 5687
Total Users : 100202
Views Today :
Views Yesterday : 51
Views Last 7 days : 321
Views Last 30 days : 1059
Views This Month : 657
Views This Year : 6821
Total views : 139267
Who's Online : 0