-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
28 lines (21 loc) · 978 Bytes
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using dotnet8_webapi_auth.Models;
using FluentValidation;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<DbConnectionFactory>(_ => new (builder.Configuration.GetConnectionString("DefaultConnection")!));
builder.Services.AddSingleton<DatabaseInitializer>();
builder.Services.AddControllers();
builder.Services.AddAuthentication(builder.Configuration);
builder.Services.AddSwaggerDocumentation();
builder.Services.AddScoped<UserRepository>();
builder.Services.AddScoped<AuthService>();
builder.Services.AddAuthorization();
builder.Services.AddTransient<IValidator<RegisterDto>, RegisterDtoValidator>();
WebApplication app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
DatabaseInitializer databaseInitializer = app.Services.GetRequiredService<DatabaseInitializer>();
await databaseInitializer.InitializeAsync();
app.Run();