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)
|
||||
.Build())
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureLocalizationSettings()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,22 +27,23 @@ namespace Oqtane
|
|||
{
|
||||
public class Startup
|
||||
{
|
||||
private static readonly string[] DefaultSupportedCultures = new[] { Constants.DefaultCulture };
|
||||
|
||||
private string _webRoot;
|
||||
private Runtime _runtime;
|
||||
private bool _useSwagger;
|
||||
private IWebHostEnvironment _env;
|
||||
private string[] _supportedCultures;
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
public Startup(IWebHostEnvironment env)
|
||||
public Startup(IWebHostEnvironment env, ILocalizationManager localizationManager)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
Configuration = builder.Build();
|
||||
|
||||
_supportedCultures = localizationManager.GetSupportedCultures();
|
||||
|
||||
_runtime = (Configuration.GetSection("Runtime").Value == "WebAssembly") ? Runtime.WebAssembly : Runtime.Server;
|
||||
|
||||
//add possibility to switch off swagger on production.
|
||||
|
@ -141,11 +142,6 @@ namespace Oqtane
|
|||
.AddSignInManager()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
var localizationSection = Configuration.GetSection("Localization");
|
||||
var localizationOptions = localizationSection.Get<LocalizationOptions>();
|
||||
|
||||
services.Configure<LocalizationOptions>(localizationSection);
|
||||
|
||||
services.Configure<IdentityOptions>(options =>
|
||||
{
|
||||
// Password settings
|
||||
|
@ -219,10 +215,7 @@ namespace Oqtane
|
|||
services.AddTransient<IUpgradeManager, UpgradeManager>();
|
||||
|
||||
// load the external assemblies into the app domain, install services
|
||||
services.AddOqtane(_runtime,
|
||||
localizationOptions.SupportedCultures.IsNullOrEmpty()
|
||||
? DefaultSupportedCultures
|
||||
: localizationOptions.SupportedCultures);
|
||||
services.AddOqtane(_runtime, _supportedCultures);
|
||||
|
||||
services.AddMvc()
|
||||
.AddNewtonsoftJson()
|
||||
|
|
Loading…
Reference in New Issue
Block a user