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