久しぶりに、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 : 51
Users Yesterday : 65
Users Last 7 days : 338
Users Last 30 days : 1388
Users This Month : 1339
Users This Year : 1339
Total Users : 95854
Views Today : 57
Views Yesterday : 76
Views Last 7 days : 416
Views Last 30 days : 1594
Views This Month : 1542
Views This Year : 1542
Total views : 133988
Who's Online : 0