The default template of ASP.NET Core Web API is given as follows.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Why are the following two statements not enabled only in development?
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
// Others are removed for the sake of simplicity.
app.Run();
As you can see, UseSwagger()
and UseSwaggerUI()
are activated only in development.
Question
I am curious why AddEndpointsApiExplorer()
and AddSwaggerGen()
are not activated only in development as well.
CodePudding user response: