Merge pull request #2348 from sbwalker/dev
Fix satellite assembly loading issue when running on WebAssembly
This commit is contained in:
commit
d0c8ee57e6
|
@ -115,7 +115,7 @@ namespace Oqtane.Controllers
|
|||
var binFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
||||
// insert satellite assemblies at beginning of list
|
||||
foreach (var culture in _localizationManager.GetSupportedCultures())
|
||||
foreach (var culture in _localizationManager.GetInstalledCultures())
|
||||
{
|
||||
var assembliesFolderPath = Path.Combine(binFolder, culture);
|
||||
if (culture == Constants.DefaultCulture)
|
||||
|
|
|
@ -29,10 +29,10 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
{
|
||||
public static class OqtaneServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddOqtane(this IServiceCollection services, string[] supportedCultures)
|
||||
public static IServiceCollection AddOqtane(this IServiceCollection services, string[] installedCultures)
|
||||
{
|
||||
LoadAssemblies();
|
||||
LoadSatelliteAssemblies(supportedCultures);
|
||||
LoadSatelliteAssemblies(installedCultures);
|
||||
services.AddOqtaneServices();
|
||||
|
||||
return services;
|
||||
|
@ -326,14 +326,14 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
}
|
||||
}
|
||||
|
||||
private static void LoadSatelliteAssemblies(string[] supportedCultures)
|
||||
private static void LoadSatelliteAssemblies(string[] installedCultures)
|
||||
{
|
||||
AssemblyLoadContext.Default.Resolving += ResolveDependencies;
|
||||
|
||||
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $"*{Constants.SatelliteAssemblyExtension}", SearchOption.AllDirectories))
|
||||
{
|
||||
var code = Path.GetFileName(Path.GetDirectoryName(file));
|
||||
if (supportedCultures.Contains(code))
|
||||
if (installedCultures.Contains(code))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ namespace Oqtane.Infrastructure
|
|||
public interface ILocalizationManager
|
||||
{
|
||||
string GetDefaultCulture();
|
||||
|
||||
string[] GetSupportedCultures();
|
||||
string[] GetInstalledCultures();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Oqtane.Models;
|
||||
using Oqtane.Shared;
|
||||
|
||||
namespace Oqtane.Infrastructure
|
||||
|
@ -29,8 +33,18 @@ namespace Oqtane.Infrastructure
|
|||
}
|
||||
|
||||
public string[] GetSupportedCultures()
|
||||
{
|
||||
{
|
||||
return CultureInfo.GetCultures(CultureTypes.AllCultures).Select(item => item.Name).OrderBy(c => c).ToArray();
|
||||
}
|
||||
|
||||
public string[] GetInstalledCultures()
|
||||
{
|
||||
var cultures = new List<string>();
|
||||
foreach (var file in Directory.EnumerateFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), $"Oqtane.Client{Constants.SatelliteAssemblyExtension}", SearchOption.AllDirectories))
|
||||
{
|
||||
cultures.Add(Path.GetFileName(Path.GetDirectoryName(file)));
|
||||
}
|
||||
return cultures.OrderBy(c => c).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Oqtane
|
|||
{
|
||||
private readonly bool _useSwagger;
|
||||
private readonly IWebHostEnvironment _env;
|
||||
private readonly string[] _supportedCultures;
|
||||
private readonly string[] _installedCultures;
|
||||
|
||||
public IConfigurationRoot Configuration { get; }
|
||||
|
||||
|
@ -35,7 +35,7 @@ namespace Oqtane
|
|||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
|
||||
Configuration = builder.Build();
|
||||
|
||||
_supportedCultures = localizationManager.GetSupportedCultures();
|
||||
_installedCultures = localizationManager.GetInstalledCultures();
|
||||
|
||||
//add possibility to switch off swagger on production.
|
||||
_useSwagger = Configuration.GetSection("UseSwagger").Value != "false";
|
||||
|
@ -91,7 +91,7 @@ namespace Oqtane
|
|||
services.AddOqtaneTransientServices();
|
||||
|
||||
// load the external assemblies into the app domain, install services
|
||||
services.AddOqtane(_supportedCultures);
|
||||
services.AddOqtane(_installedCultures);
|
||||
services.AddOqtaneDbContext();
|
||||
|
||||
services.AddAntiforgery(options =>
|
||||
|
|
Loading…
Reference in New Issue
Block a user