-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
52 lines (42 loc) · 1.51 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
using Casheesh.Models;
using Casheesh.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using System;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Set Culture Environment Variable if empty
string culture = Environment.GetEnvironmentVariable("CULTURE") ?? Environment.GetEnvironmentVariable("Culture") ?? Environment.GetEnvironmentVariable("culture") ?? "en-US";
Environment.SetEnvironmentVariable("CULTURE", culture);
builder.Services.AddHostedService<CasheeshService>();
builder.Services.AddDbContext<CasheeshContext>();
builder.Services.AddLocalization();
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
WebApplication app = builder.Build();
using (IServiceScope scope = app.Services.CreateAsyncScope())
{
CasheeshContext casheeshContext = scope.ServiceProvider.GetRequiredService<CasheeshContext>();
casheeshContext.Database.Migrate();
}
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseRequestLocalization(Environment.GetEnvironmentVariable("CULTURE") ?? "en-CA");
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.MapControllers();
app.Run();