Program.cs (774B)
1 using Api.Data; 2 using Microsoft.EntityFrameworkCore; 3 using Microsoft.Extensions.Configuration; 4 5 var builder = WebApplication.CreateBuilder(args); 6 7 // Add services to the container. 8 9 builder.Services.AddControllers(); 10 // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 11 builder.Services.AddEndpointsApiExplorer(); 12 builder.Services.AddSwaggerGen(); 13 14 builder.Services.AddDbContext<AppDbContext>(options => 15 options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"))); 16 17 var app = builder.Build(); 18 19 // Configure the HTTP request pipeline. 20 if (app.Environment.IsDevelopment()) 21 { 22 app.UseSwagger(); 23 app.UseSwaggerUI(); 24 } 25 26 app.UseHttpsRedirection(); 27 28 app.UseAuthorization(); 29 30 app.MapControllers(); 31 32 app.Run();