-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
114 lines (88 loc) · 2.9 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
using Microsoft.EntityFrameworkCore;
using Hanum.Core.Helpers;
using Hanum.Core.Protos;
using Hanum.Pay.Contexts;
using Hanum.Pay.Services;
using Hanum.Core.Authentication;
using Hanum.Core.Middleware;
using Hanum.Pay.Core.Authentication;
using Microsoft.AspNetCore.Authentication;
using Hanum.Pay.Contracts.Services;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
var services = builder.Services;
builder.WebHost.UseStaticWebAssets();
services.AddHanumLogging();
services.AddCors(options => {
options.AddPolicy(
name: "AllowAll",
policyBuilder => {
policyBuilder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}
);
options.AddPolicy(
name: "AllowCors",
policyBuilder => {
policyBuilder.WithOrigins(configuration.GetSection("AllowedCorsOrigins").Get<string[]>()!)
.AllowAnyMethod()
.AllowAnyHeader();
}
);
});
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddControllers();
services.AddHanumSwaggerGen();
// DB Context
services.AddHanumDbContexts<HanumContext>(
configuration.GetConnectionString("Database.SQL"),
configuration.GetSection("Database"));
// Redis Cache
services.AddStackExchangeRedisCache(options => {
options.Configuration = configuration.GetConnectionString("Cache.Redis");
});
// gRPC Client
services.AddHanumAuthGrpcClient(
configuration.GetConnectionString("AuthService.gRPC")!);
// Authentication Handler
services.AddAuthentication()
.AddHanumCommonAuthScheme()
.AddScheme<AuthenticationSchemeOptions, HanumBoothAuthenticationHandler>(HanumBoothAuthenticationHandler.SchemeName, null);
// Services
services.AddTransient<IEoullimBoothService, EoullimBoothService>();
services.AddTransient<IEoullimBalanceService, EoullimBalanceService>();
services.AddSingleton<IEoullimDashboardService, EoullimDashboardService>();
var app = builder.Build();
using (var serviceScope = app.Services.GetService<IServiceScopeFactory>()!.CreateScope()) {
var context = serviceScope.ServiceProvider.GetRequiredService<HanumContext>();
foreach (var sqls in Directory.GetFiles("Migrations/hanum", "*.sql").OrderBy(x => x)) {
var sql = File.ReadAllText(sqls);
try {
context.Database.ExecuteSqlRaw(sql);
} catch {
if (sqls.Contains('!'))
throw;
}
}
}
if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
app.UseHsts();
app.UseCors("AllowAll");
} else {
app.UseExceptionHandler("/Error");
app.UseCors("AllowCors");
}
app.UseMiddleware<RequestLoggingMiddleware>();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();