-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (89 loc) · 4.53 KB
/
Program.cs
File metadata and controls
107 lines (89 loc) · 4.53 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
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
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using WatchMNS.Database;
using WatchMNS.Models;
using WatchMNS.Repository.Interfaces;
using WatchMNS.Repository;
using WatchMNS.Services.Interfaces;
using WatchMNS.Services;
namespace WatchMNS
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<DatabaseContext>()
.AddIdentity<Client, IdentityRole>(options =>
{
options.Password.RequiredLength = 8;
options.Password.RequireLowercase = true;
options.Password.RequireUppercase = true;
options.Lockout.MaxFailedAccessAttempts = 5;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<DatabaseContext>();
// Repositories
builder.Services.AddScoped<ClientRepository>();
builder.Services.AddScoped<DocumentRepository>();
builder.Services.AddScoped<DocumentStatusRepository>();
builder.Services.AddScoped<DocumentTypeRepository>();
builder.Services.AddScoped<LateMissDocRepository>();
builder.Services.AddScoped<LateMissRepository>();
builder.Services.AddScoped<LateMissStatusRepository>();
builder.Services.AddScoped<NotificationRepository>();
builder.Services.AddScoped<NotificationTypeRepository>();
builder.Services.AddScoped<ProfessionnalStatusRepository>();
builder.Services.AddScoped<TrainingRepository>();
builder.Services.AddScoped<TrainingTypeRepository>();
// Services
builder.Services.AddScoped(typeof(IService<>), typeof(Service<>));
builder.Services.AddScoped<IClientService, ClientService>();
builder.Services.AddScoped<IDocumentService, DocumentService>();
builder.Services.AddScoped<IDocumentStatusService, DocumentStatusService>();
builder.Services.AddScoped<IDocumentTypeService, DocumentTypeService>();
builder.Services.AddScoped<ILateMissDocService, LateMissDocService>();
builder.Services.AddScoped<ILateMissService, LateMissService>();
builder.Services.AddScoped<ILateMissStatusService, LateMissStatusService>();
builder.Services.AddScoped<INotificationService, NotificationService>();
builder.Services.AddScoped<INotificationTypeService, NotificationTypeService>();
builder.Services.AddScoped<IProfessionnalStatusService, ProfessionnalStatusService>();
builder.Services.AddScoped<ITrainingService, TrainingService>();
builder.Services.AddScoped<ITrainingTypeService, TrainingTypeService>();
var roleManager = builder.Services.BuildServiceProvider().GetRequiredService<RoleManager<IdentityRole>>();
var roles = new[] { "Admin", "Moderator", "User", "Guest" };
foreach (var role in roles)
{
if (!await roleManager.RoleExistsAsync(role))
{
await roleManager.CreateAsync(new IdentityRole(role));
}
}
builder.Services.ConfigureApplicationCookie(options =>
{
options.LoginPath = "/Security/AccessDenied";
options.AccessDeniedPath = "/Security/AccessDenied";
});
// Add services to the container.
builder.Services.AddControllersWithViews();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Account}/{action=Login}/{id?}");
app.Run();
}
}
}