-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (49 loc) · 1.89 KB
/
Copy pathProgram.cs
File metadata and controls
61 lines (49 loc) · 1.89 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
using DevExtremeVSTemplateMVC.DAL;
using DevExtremeVSTemplateMVC.Middleware;
using DevExtremeVSTemplateMVC.Services;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var viewBuilder = builder.Services.AddControllersWithViews();
#if DEBUG
builder.Services.AddSassCompiler();
#endif
viewBuilder.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);
if (builder.Environment.IsDevelopment()) {
viewBuilder.AddRazorRuntimeCompilation();
}
builder.Services.AddHttpClient();
builder.Services.AddMemoryCache();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IDbConnectionAccessor, DbConnectionAccessor>();
builder.Services.AddScoped<DemoDbContext>(provider => {
var conn = provider.GetRequiredService<IDbConnectionAccessor>().GetConnection();
var options = new DbContextOptionsBuilder<DemoDbContext>()
.UseSqlite(conn)
.Options;
return new DemoDbContext(options);
});
builder.Services.AddScoped<IDataSeeder, DataSeeder>();
builder.Services.AddScoped<LocalDemoDataContext>();
builder.Services.AddSession(options => {
options.IdleTimeout = SessionDbContextMiddleware.CACHE_IDLE_TIMEOUT;
});
var app = builder.Build();
app.Lifetime.ApplicationStarted.Register(async () => {
using var scope = app.Services.CreateScope();
var httpClient = scope.ServiceProvider.GetRequiredService<HttpClient>();
DemoDataFetcher.DownloadTask = DemoDataFetcher.Download(httpClient, builder.Configuration);
await DemoDataFetcher.DownloadTask;
});
if (!app.Environment.IsDevelopment()) {
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseSession();
app.UseMiddleware<SessionDbContextMiddleware>();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();