-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
81 lines (59 loc) · 2.25 KB
/
Program.cs
File metadata and controls
81 lines (59 loc) · 2.25 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using AeonRegistryAPI.Endpoints.CustomIndentityEndpoints;
using AeonRegistryAPI.Endpoints.Home;
using AeonRegistryAPI.Services;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.UI.Services;
using Microsoft.EntityFrameworkCore;
using AeonRegistryAPI.Services.Interfaces;
using AeonRegistryAPI.Endpoints.Sites;
using AeonRegistryAPI.Endpoints.Artifact;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddCustomSwagger();
//get a connection to the database
var connectionString = DataUtility.GetConnectionString(builder.Configuration);
//Configure the database context for PostgreSQL
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(connectionString));
//add indentity endpoints
builder.Services.AddIdentityApiEndpoints<ApplicationUser>(options =>
{
options.SignIn.RequireConfirmedAccount = false;
})
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
//Admin Policy
builder.Services.AddAuthorizationBuilder()
.AddPolicy("AdminOnly", policy => policy.RequireRole("Admin"));
//Email Sender Service
builder.Services.AddTransient<IEmailSender, ConsoleEmailService>();
//custom services
builder.Services.AddScoped<ISiteService, SiteService>();
builder.Services.AddScoped<IArtifactMediaFileService, ArtifactMediaFileService>();
builder.Services.AddScoped<IArtifactService, ArtifactService>();
//enable validation for minimal APIs
builder.Services.AddValidation();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
using (var scope = app.Services.CreateScope())
{
await DataSeed.ManageDataAsync(scope.ServiceProvider);
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseMiddleware<BlockIdentityEndpoints>();
var authRouteGroup = app.MapGroup("/api/auth")
.WithTags("Admin");
authRouteGroup.MapIdentityApi<ApplicationUser>();
app.MapGet("/", () => Results.Redirect("/index.html"));
app.MapCustomIdentityEndpoints();
app.MapSiteEndpoints();
app.MapArtifactEndpoints();
app.MapArtifactMediaFileEndpoints();
app.MapHomeEndpoints();
app.Run();