|
@@ -1,5 +1,6 @@
|
|
|
using System;
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
|
+using System.Globalization;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Reflection;
|
|
using System.Reflection;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
@@ -9,7 +10,9 @@ using GreenTree.Strohrmann.ERP.Domain.Model;
|
|
|
using GreenTree.Strohrmann.ERP.Services.Authentication;
|
|
using GreenTree.Strohrmann.ERP.Services.Authentication;
|
|
|
using GreenTree.Strohrmann.ERP.Services.Authorization;
|
|
using GreenTree.Strohrmann.ERP.Services.Authorization;
|
|
|
using GreenTree.Strohrmann.ERP.Services.Geolocator;
|
|
using GreenTree.Strohrmann.ERP.Services.Geolocator;
|
|
|
|
|
+using GreenTree.Strohrmann.ERP.Services.Localization;
|
|
|
using GreenTree.Strohrmann.ERP.Services.Notification;
|
|
using GreenTree.Strohrmann.ERP.Services.Notification;
|
|
|
|
|
+using GreenTree.Strohrmann.ERP.Web.Configuration;
|
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
using Microsoft.AspNetCore.Authentication.Cookies;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
@@ -17,11 +20,14 @@ using Microsoft.AspNetCore.Builder;
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
using Microsoft.AspNetCore.HttpsPolicy;
|
|
|
|
|
+using Microsoft.AspNetCore.Localization;
|
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
|
|
+using Porta.Kundenzähler.Services.Extension;
|
|
|
|
|
|
|
|
namespace GreenTree.Strohrmann.ERP.Web
|
|
namespace GreenTree.Strohrmann.ERP.Web
|
|
|
{
|
|
{
|
|
@@ -71,6 +77,7 @@ namespace GreenTree.Strohrmann.ERP.Web
|
|
|
|
|
|
|
|
// Add option handling
|
|
// Add option handling
|
|
|
services.AddOptions();
|
|
services.AddOptions();
|
|
|
|
|
+ services.AddSingleton(typeof(IOptionsMonitor<>), typeof(OptionsMonitor<>));
|
|
|
|
|
|
|
|
// Add the HttpContextAccessor as Singleton
|
|
// Add the HttpContextAccessor as Singleton
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
@@ -83,13 +90,11 @@ namespace GreenTree.Strohrmann.ERP.Web
|
|
|
|
|
|
|
|
services.AddSingleton(administrationOptions);
|
|
services.AddSingleton(administrationOptions);
|
|
|
|
|
|
|
|
- // Add global mail notification options
|
|
|
|
|
- var mailNotificationOptions = Configuration.GetSection("MailNotificationOptions").Get<MailNotificationOptions>();
|
|
|
|
|
-
|
|
|
|
|
- if (mailNotificationOptions == null)
|
|
|
|
|
|
|
+ // Add MailConfigurationOptions monitor
|
|
|
|
|
+ if (!Configuration.SectionExists("MailNotificationOptions"))
|
|
|
throw new Exception("The appsettings.json does not contain mail notification options.");
|
|
throw new Exception("The appsettings.json does not contain mail notification options.");
|
|
|
|
|
|
|
|
- services.AddSingleton<IMailNotificationOptions>(mailNotificationOptions);
|
|
|
|
|
|
|
+ services.Configure<MailNotificationOptions>(Configuration.GetSection("MailNotificationOptions"));
|
|
|
|
|
|
|
|
// Add the mail notification service
|
|
// Add the mail notification service
|
|
|
services.AddSingleton<INotificationService, MailNotificationService>();
|
|
services.AddSingleton<INotificationService, MailNotificationService>();
|
|
@@ -105,6 +110,27 @@ namespace GreenTree.Strohrmann.ERP.Web
|
|
|
// Add the Google Geocoding service
|
|
// Add the Google Geocoding service
|
|
|
services.AddSingleton<IGeocodingService, GoogleGeocodingService>();
|
|
services.AddSingleton<IGeocodingService, GoogleGeocodingService>();
|
|
|
|
|
|
|
|
|
|
+ // Add global culture options
|
|
|
|
|
+ services.Configure<CultureOptions>(Configuration.GetSection("CultureOptions"));
|
|
|
|
|
+
|
|
|
|
|
+ // Add localization
|
|
|
|
|
+ services.Configure<RequestLocalizationOptions>(options =>
|
|
|
|
|
+ {
|
|
|
|
|
+ // Add global culture options
|
|
|
|
|
+ var cultureOptions = Configuration.GetSection("CultureOptions").Get<CultureOptions>();
|
|
|
|
|
+
|
|
|
|
|
+ var culture = cultureOptions == null || (cultureOptions.DefaultCulture != null && String.IsNullOrEmpty(cultureOptions.DefaultCulture))
|
|
|
|
|
+ ? CultureInfo.CurrentCulture.Name
|
|
|
|
|
+ : cultureOptions.DefaultCulture;
|
|
|
|
|
+
|
|
|
|
|
+ options.DefaultRequestCulture = new RequestCulture(culture);
|
|
|
|
|
+ options.RequestCultureProviders = new List<IRequestCultureProvider>
|
|
|
|
|
+ {
|
|
|
|
|
+ new QueryStringRequestCultureProvider(),
|
|
|
|
|
+ new CookieRequestCultureProvider()
|
|
|
|
|
+ };
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
// Add sessioning
|
|
// Add sessioning
|
|
|
services.AddSession(options =>
|
|
services.AddSession(options =>
|
|
|
{
|
|
{
|
|
@@ -168,6 +194,9 @@ namespace GreenTree.Strohrmann.ERP.Web
|
|
|
|
|
|
|
|
// Add the DbContext custom authorization service
|
|
// Add the DbContext custom authorization service
|
|
|
services.AddScoped<Services.Authorization.IAuthorizationService, CookieAuthorizationService>();
|
|
services.AddScoped<Services.Authorization.IAuthorizationService, CookieAuthorizationService>();
|
|
|
|
|
+
|
|
|
|
|
+ // Add the option monitoring service
|
|
|
|
|
+ services.AddSingleton<IOptionMonitoringService, DefaultOptionMonitoringService>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
@@ -181,7 +210,9 @@ namespace GreenTree.Strohrmann.ERP.Web
|
|
|
{
|
|
{
|
|
|
app.UseExceptionHandler("/Home/Error");
|
|
app.UseExceptionHandler("/Home/Error");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
app.UseStaticFiles();
|
|
app.UseStaticFiles();
|
|
|
|
|
+ app.UseRequestLocalization();
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
app.UseRouting();
|
|
|
|
|
|