-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
77 lines (62 loc) · 2.73 KB
/
Program.cs
File metadata and controls
77 lines (62 loc) · 2.73 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using BudgetApp.Data;
using BudgetApp.Data.Repositories;
using BudgetApp.Models;
using BudgetApp.Resources;
using NLog;
using NLog.Web;
// Early init of NLog to allow startup and exception logging, before host is built
var logger = NLog.LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
logger.Debug("init main");
try
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews()
.AddDataAnnotationsLocalization(options => {
options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(DataAnnotations));
});
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
// Dependency Injection for Repositories
builder.Services.AddScoped<DapperContext>();
builder.Services.AddScoped<IBudgetRepository<BudgetModel>, BudgetRepository<BudgetModel>>();
builder.Services.AddScoped<ICampRepository<CampModel>, CampRepository<CampModel>>();
builder.Services.AddScoped<ICategoryRepository<CategoryModel>, CategoryRepository<CategoryModel>>();
builder.Services.AddScoped<IPositionRepository<PositionModel>, PositionRepository<PositionModel>>();
builder.Services.AddScoped<IPositionTypeRepository<PositionTypeModel>, PositionTypeRepository<PositionTypeModel>>();
builder.Services.AddScoped<ISubCategoryRepository<SubCategoryModel>, SubCategoryRepository<SubCategoryModel>>();
builder.Services.AddScoped<ITemplateBudgetRepository<TemplateBudgetModel>, TemplateBudgetRepository<TemplateBudgetModel>>();
builder.Services.AddScoped<ITemplatePositionRepository<TemplatePositionModel>, TemplatePositionRepository<TemplatePositionModel>>();
// NLog: Setup NLog for Dependency injection
builder.Logging.ClearProviders();
builder.Host.UseNLog();
var app = builder.Build();
var supportedCultures = new[] { "de-CH" };
var localizationOptions = new RequestLocalizationOptions()
.SetDefaultCulture("de-CH")
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures);
app.UseRequestLocalization(localizationOptions);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
}
catch (Exception ex)
{
logger.Error(ex, "Stopped program because of exception");
throw;
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit
LogManager.Shutdown();
}