-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
128 lines (98 loc) · 3.91 KB
/
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using Indotalent;
using Indotalent.AppSettings;
using Indotalent.Data;
using Indotalent.Infrastructures.Middlewares;
using Indotalent.Infrastructures.ODatas;
using Indotalent.Infrastructures.Pdfs;
using Indotalent.Models.Entities;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using WkHtmlToPdfDotNet;
using WkHtmlToPdfDotNet.Contracts;
var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
builder.Services
.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
builder.Services
.AddDatabaseDeveloperPageExceptionFilter();
builder.Services
.Configure<IdentitySettings>(builder.Configuration.GetSection(IdentitySettings.IdentitySettingsName));
builder.Services
.AddIdentity<ApplicationUser, IdentityRole>(options =>
{
var identitySettings = builder.Configuration.GetSection(IdentitySettings.IdentitySettingsName).Get<IdentitySettings>();
if (identitySettings != null)
{
options.SignIn.RequireConfirmedAccount = identitySettings.RequireConfirmedAccount;
options.Password.RequireDigit = identitySettings.RequireDigit;
options.Password.RequiredLength = identitySettings.RequiredLength;
options.Password.RequireNonAlphanumeric = identitySettings.RequireNonAlphanumeric;
options.Password.RequireUppercase = identitySettings.RequireUppercase;
options.Password.RequireLowercase = identitySettings.RequireLowercase;
options.Lockout.DefaultLockoutTimeSpan = identitySettings.DefaultLockoutTimeSpan;
options.Lockout.MaxFailedAccessAttempts = identitySettings.MaxFailedAccessAttempts;
}
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddRoles<IdentityRole>()
.AddDefaultTokenProviders();
builder.Services
.ConfigureApplicationCookie(options =>
{
var appConfig = builder.Configuration.GetSection("ApplicationConfiguration").Get<ApplicationConfiguration>();
if (appConfig != null)
{
options.LoginPath = appConfig.LoginPage;
options.LogoutPath = appConfig.LogoutPage;
options.AccessDeniedPath = appConfig.AccessDeniedPage;
}
});
builder.Services
.Configure<SmtpConfiguration>(builder.Configuration.GetSection("SmtpConfiguration"));
builder.Services
.Configure<RegistrationConfiguration>(builder.Configuration.GetSection("RegistrationConfiguration"));
builder.Services.
Configure<ApplicationConfiguration>(builder.Configuration.GetSection("ApplicationConfiguration"));
builder.Services.AddRazorPages();
builder.Services
.AddAllCustomServices();
builder.Services
.AddAutoMapper(typeof(Program));
builder.Services
.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
builder.Services
.AddSingleton<IPdfService, PdfService>();
builder.Services
.AddCustomOData();
builder.Services
.AddSession();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
}
else
{
app.UseExceptionHandler("/Error");
}
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<ApplicationDbContext>();
var appConfig = services.GetRequiredService<IOptions<ApplicationConfiguration>>();
if (appConfig.Value.IsDevelopment)
{
context.Database.EnsureCreated();//<===*** Development Only !!! ***
}
await DbInitializer.InitializeAsync(services);
}
app.UseStaticFiles();
app.UseSession();
app.UseMiddleware<LogAnalyticMiddleware>();
app.UseMiddleware<GlobalErrorHandlingMiddleware>();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.MapControllers();
app.Run();