2021-07-21 06:58:49 +00:00
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Runtime.Loader;
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
2021-08-07 22:20:46 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2021-07-22 21:12:27 +00:00
|
|
|
using Props.Shop.Framework;
|
2021-07-21 06:58:49 +00:00
|
|
|
|
|
|
|
namespace Props.Services.Modules
|
|
|
|
{
|
|
|
|
internal class ShopAssemblyLoadContext : AssemblyLoadContext
|
|
|
|
{
|
|
|
|
private AssemblyDependencyResolver resolver;
|
|
|
|
|
|
|
|
public ShopAssemblyLoadContext(string path)
|
|
|
|
{
|
|
|
|
resolver = new AssemblyDependencyResolver(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Assembly Load(AssemblyName assemblyName)
|
|
|
|
{
|
2021-07-22 21:12:27 +00:00
|
|
|
if (assemblyName.FullName.Equals(typeof(IShop).Assembly.FullName)) return null;
|
2021-08-07 22:20:46 +00:00
|
|
|
if (assemblyName.FullName.Equals(typeof(ILoggerFactory).Assembly.FullName)) return null;
|
2021-07-21 06:58:49 +00:00
|
|
|
string assemblyPath = resolver.ResolveAssemblyToPath(assemblyName);
|
|
|
|
return assemblyPath != null ? LoadFromAssemblyPath(assemblyPath) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
|
|
|
|
{
|
|
|
|
string libPath = resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
|
|
|
|
return libPath != null ? LoadUnmanagedDllFromPath(libPath) : IntPtr.Zero;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|