using LingAdmin.API.Data; using LingAdmin.API.Services; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers().AddDapr(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); // Register custom services builder.Services.AddScoped(); builder.Services.AddScoped(); // Configure CORS builder.Services.AddCors(options => { options.AddPolicy("AllowAll", policy => { policy.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); }); }); // Add DbContext with SQL Server builder.Services.AddDbContext(options => options.UseSqlServer( builder.Configuration.GetConnectionString("DefaultConnection"), b => b.MigrationsAssembly("LingAdmin.API") ) ); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseCors("AllowAll"); app.UseAuthorization(); app.UseCloudEvents(); app.MapControllers(); app.MapSubscribeHandler(); // Auto migrate database using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService(); db.Database.Migrate(); } app.Run();