-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (48 loc) · 1.46 KB
/
Copy pathProgram.cs
File metadata and controls
60 lines (48 loc) · 1.46 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
using TuesberryAPIServer;
using TuesberryAPIServer.Middleware;
using TuesberryAPIServer.Services;
using ZLogger;
var builder = WebApplication.CreateBuilder(args);
// Add services
builder.Services.AddLogging();
builder.Services.AddControllers();
// http context accessor
builder.Services.AddHttpContextAccessor();
// dbconfig option binding
IConfiguration configuration = builder.Configuration;
builder.Services.Configure<DbConfig>(configuration.GetSection(nameof(DbConfig)));
// add db services
builder.Services.AddTransient<IGameDb, GameDb>();
builder.Services.AddTransient<IAccountDb, AccountDb>();
builder.Services.AddSingleton<IMemoryDb, RedisDb>();
builder.Services.AddSingleton<IMasterDb, MasterdataDb>();
// log ¼³Á¤
builder.Logging.ClearProviders();
builder.Logging.AddZLoggerConsole();
/*
builder.Logging.AddZLoggerConsole(options =>
{
options.EnableStructuredLogging = true;
});
*/
// build app
var app = builder.Build();
// Configure the HTTP request pipeline.
if(!app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
// add check middleware
app.UseCheckUserVersion();
app.UseCheckUserAuth();
// use routing
app.UseRouting();
app.MapControllers();
//redis init
var redisDb = app.Services.GetRequiredService<IMemoryDb>();
redisDb.Init(configuration.GetSection("DbConfig")["Redis"]);
// master data init
var masterdataDb = app.Services.GetRequiredService<IMasterDb>();
masterdataDb.Init();
// running app
app.Run(configuration["ServerAddress"]);