props/Props/Services/Modules/ShopAssemblyLoadContext.cs
Harrison Deng 38ffb3c7e1 Added logging to module framework
Implemented logging to Adafruit and changed database loading behavior.
2021-08-07 17:20:46 -05:00

33 lines
1.2 KiB
C#

using System;
using System.Reflection;
using System.Runtime.Loader;
using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.Logging;
using Props.Shop.Framework;
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)
{
if (assemblyName.FullName.Equals(typeof(IShop).Assembly.FullName)) return null;
if (assemblyName.FullName.Equals(typeof(ILoggerFactory).Assembly.FullName)) return null;
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;
}
}
}