Hi @65810666 ,
ASP.NET 6 Minimal Hosting Model Vs. Minimal API
They are different technologies.
The Asp.Net 6 minimal hosting model:
- Significantly reduces the number of files and lines of code required to create an app. Only one file is needed with four lines of code.
- Unifies Startup.cs and Program.cs into a single Program.cs file.
- Uses top-level statements to minimize the code required for an app.
- Uses global using directives to eliminate or minimize the number of using statement lines required.
For example, when using Asp.Net 5 (or previous version) Web App template to generate the application, the project contains the Startup.cs file and Program.cs file. But in Asp.net 6, it will use the minimal hosting model, the preceding code is replaced by the following:
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
More detail information, see New hosting model.
For the Minimal API, as the name suggests, it is a minimal version of the API application.
Generally, when we create a Asp.net Core API application, instead of the Minimal API application, it will create a Controller folder, and we can use the app.MapControllers();
to configure the route. When you want to add a new end point, you can add a new API controller in the Controller folder, and then add the relates action method.
But when we create a Minimal API application, there doesn't have the controller folder. The endpoints are all in the Program.cs file (use app.MapGet, app.MapPost and so on):
More detail information, see Tutorial: Create a minimal web API with ASP.NET Core
Differences between minimal APIs and APIs with controllers
So, the Minimal Hosting Model and Minimal API are two different features in the Asp.Net 6.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Dillion