using Microsoft.EntityFrameworkCore; using NetCoreV2.DataAccesLayer; var 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(); builder.Services.AddDbContext<Context>(); var app = builder.Build(); using (var scope = app.Services.CreateScope()) { var db = scope.ServiceProvider.GetRequiredService<Context>(); db.Database.Migrate(); } if (app.Environment.IsDevelopment() || app.Environment.IsProduction()) { app.UseDeveloperExceptionPage(); app.UseSwagger(); app.UseSwaggerUI(c =>{ c.SwaggerEndpoint("/swagger/v1/swagger.json", "myapi v1"); }) ; } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.Run(); |