Giải thích quá trình khởi động trong ASP.NET Core?
Giải thích quá trình khởi động trong ASP.NET Core?
Quá trình khởi động ASP.NET Core (.NET 6+ dùng minimal hosting model trong Program.cs):
var builder = WebApplication.CreateBuilder(args); // 1. Host + cấu hình mặc định + Kestrel
// 2. Đăng ký dịch vụ (DI)
builder.Services.AddControllers();
builder.Services.AddDbContext<AppDbContext>(o => o.UseSqlServer(builder.Configuration.GetConnectionString("Default")));
builder.Services.AddAuthentication().AddJwtBearer();
var app = builder.Build(); // 3. Dựng host + DI container
// 4. Cấu hình middleware pipeline (thứ tự quan trọng)
if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/error"); app.UseHsts(); }
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.