在ASP.NET 5中动态加载程序集 [英] Dynamically load assemblies in ASP.NET 5

查看:331
本文介绍了在ASP.NET 5中动态加载程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾经有一些代码,可以扫描我的应用程序的bin目录中是否存在尚未加载到AppDomain中的程序集,并已加载它们.基本上看起来像这样:

I used to have some code which scanned the bin directory of my application for assemblies which weren't loaded in the AppDomain yet and loaded them. It basically looked like:

foreach (var assemblyPath in Directory.GetFiles("path\to\bin", "*.dll"))
{
    var inspected = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
    Assembly.Load(inspected.GetName());
}

为简洁起见,我跳过了try/catch子句等.

这使我可以在运行时将具有某些接口实现的程序集拖放到bin文件夹中,并让IoC容器自动拾取它们.现在有了新的Roslyn魔术,调试时就不再需要物理DLL.有没有办法动态地检索程序集名称,项目名称或依赖项名称(在project.json中).

This allowed me to drop assemblies in the bin folder at run-time with implementations for certain interfaces and let the IoC container pick them up automatically. Now with the new Roslyn magic, there are no physical DLL's anymore when debugging. Is there any way to retrieve assembly names, project names or dependency names (in project.json) dynamically.

我想我必须实现此示例在熵存储库中,但是我不知道如何为我的场景实现它.

I guess I have to implement something like this example in the Entropy repo, but I don't know how to implement it for my scenario.

推荐答案

您正在寻找的是

What you are looking for is ILibraryManager implementation which provides access to the complete graph of dependencies for the application. This is already flowed through the ASP.NET 5 DI system. So, you can reach out to it from there.

示例用法可以在 RoslynCompilationService .

这篇关于在ASP.NET 5中动态加载程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆