Simplify localization settings configurations
This commit is contained in:
parent
7b1a2fb887
commit
86bb6d1ea8
21
Oqtane.Server/Extensions/WebHostBuilderExtensions.cs
Normal file
21
Oqtane.Server/Extensions/WebHostBuilderExtensions.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using Oqtane.Infrastructure;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.Hosting
|
||||||
|
{
|
||||||
|
public static class WebHostBuilderExtensions
|
||||||
|
{
|
||||||
|
public static IWebHostBuilder ConfigureLocalizationSettings(this IWebHostBuilder builder)
|
||||||
|
{
|
||||||
|
return builder.ConfigureServices((context, services) =>
|
||||||
|
{
|
||||||
|
var config = context.Configuration;
|
||||||
|
|
||||||
|
services.Configure<LocalizationOptions>(config.GetSection("Localization"));
|
||||||
|
services.AddSingleton(ctx => ctx.GetService<IOptions<LocalizationOptions>>().Value);
|
||||||
|
services.AddTransient<ILocalizationManager, LocalizationManager>();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ namespace Oqtane.Server
|
||||||
.AddCommandLine(args)
|
.AddCommandLine(args)
|
||||||
.Build())
|
.Build())
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
|
.ConfigureLocalizationSettings()
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,22 +27,23 @@ namespace Oqtane
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
private static readonly string[] DefaultSupportedCultures = new[] { Constants.DefaultCulture };
|
|
||||||
|
|
||||||
private string _webRoot;
|
private string _webRoot;
|
||||||
private Runtime _runtime;
|
private Runtime _runtime;
|
||||||
private bool _useSwagger;
|
private bool _useSwagger;
|
||||||
private IWebHostEnvironment _env;
|
private IWebHostEnvironment _env;
|
||||||
|
private string[] _supportedCultures;
|
||||||
|
|
||||||
public IConfigurationRoot Configuration { get; }
|
public IConfigurationRoot Configuration { get; }
|
||||||
|
|
||||||
public Startup(IWebHostEnvironment env)
|
public Startup(IWebHostEnvironment env, ILocalizationManager localizationManager)
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.SetBasePath(env.ContentRootPath)
|
.SetBasePath(env.ContentRootPath)
|
||||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
|
|
||||||
|
_supportedCultures = localizationManager.GetSupportedCultures();
|
||||||
|
|
||||||
_runtime = (Configuration.GetSection("Runtime").Value == "WebAssembly") ? Runtime.WebAssembly : Runtime.Server;
|
_runtime = (Configuration.GetSection("Runtime").Value == "WebAssembly") ? Runtime.WebAssembly : Runtime.Server;
|
||||||
|
|
||||||
//add possibility to switch off swagger on production.
|
//add possibility to switch off swagger on production.
|
||||||
|
@ -141,11 +142,6 @@ namespace Oqtane
|
||||||
.AddSignInManager()
|
.AddSignInManager()
|
||||||
.AddDefaultTokenProviders();
|
.AddDefaultTokenProviders();
|
||||||
|
|
||||||
var localizationSection = Configuration.GetSection("Localization");
|
|
||||||
var localizationOptions = localizationSection.Get<LocalizationOptions>();
|
|
||||||
|
|
||||||
services.Configure<LocalizationOptions>(localizationSection);
|
|
||||||
|
|
||||||
services.Configure<IdentityOptions>(options =>
|
services.Configure<IdentityOptions>(options =>
|
||||||
{
|
{
|
||||||
// Password settings
|
// Password settings
|
||||||
|
@ -219,10 +215,7 @@ namespace Oqtane
|
||||||
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
||||||
|
|
||||||
// load the external assemblies into the app domain, install services
|
// load the external assemblies into the app domain, install services
|
||||||
services.AddOqtane(_runtime,
|
services.AddOqtane(_runtime, _supportedCultures);
|
||||||
localizationOptions.SupportedCultures.IsNullOrEmpty()
|
|
||||||
? DefaultSupportedCultures
|
|
||||||
: localizationOptions.SupportedCultures);
|
|
||||||
|
|
||||||
services.AddMvc()
|
services.AddMvc()
|
||||||
.AddNewtonsoftJson()
|
.AddNewtonsoftJson()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user