-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
94 lines (71 loc) · 2.98 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
using Microsoft.EntityFrameworkCore;
using UserHelpPageTemplate.Business;
using DataLayer;
using Business;
using AutoMapper;
using UserHelpPageTemplate.Infrastructure;
using Microsoft.AspNetCore.Identity;
using Serilog;
using AppLogger;
using UserHelpPageTemplate.Areas.Identity.Data;
var builder = WebApplication.CreateBuilder(args);
#region DbContexts
var connectionString = builder.Configuration.GetConnectionString("UHPIdentityDbContext") ?? throw new InvalidOperationException("Connection string 'IdentityDbContext' not found.");
builder.Services.AddDbContext<UHPIdentityDbContext>(options => options.UseSqlServer(connectionString));
//old version auto generated
//builder.Services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<UHPIdentityDbContext>();
// adjust this to work with new user
builder.Services.AddIdentity<ApplicationUser, ApplicationRole>(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<UHPIdentityDbContext>()
.AddDefaultUI()
.AddDefaultTokenProviders();
builder.Services.AddEntityFrameworkSqlServer().AddDbContext<UserHelpPageDbContext>(options =>
{
options.UseSqlServer(
builder.Configuration["ConnectionStrings:UserHelpPagDbContextConnection"]);
});
#endregion DbContexts
#region Scoping
// Add services to the container.
// service to add MVC support
//AddScoped: This means that the DI container will create a single instance of the object per HTTP request (in the case of web applications)
//Within the same request, each time the service is requested,the same instance will be returned.
builder.Services.AddScoped<IRepository, Repository>();
builder.Services.AddScoped<IBiz, Biz>();
builder.Services.AddScoped<IExcelService, ExcelService>();
builder.Services.AddAutoMapper(typeof(AutoMapperProfiles).Assembly);
builder.Services.AddScoped<IMapper, Mapper>();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddHttpContextAccessor();
builder.Services.AddControllersWithViews();
#endregion Scoping
#region Logger Services
Log.Logger = new LoggerConfiguration().ReadFrom.Configuration(builder.Configuration).Enrich.FromLogContext().CreateLogger();
builder.Services.AddLogging(x =>
{
x.ClearProviders();
x.AddSerilog();
});
//FOR LOGGER
builder.Services.AddScoped<IUserHelpPageLogger, UserHelpPageLogger>();
#endregion
#region MiddleWear
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();
}
// add middlewear files
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/app/{catchall}","/App/index");
app.UseAuthorization();
//end point middle wear
app.MapDefaultControllerRoute();
#endregion MiddleWear
app.Run();