【问题标题】:Loading modules from all assemblies with Ninject and wpf使用 Ninject 和 wpf 从所有程序集中加载模块
【发布时间】:2013-07-28 07:01:32
【问题描述】:

我使用这个article 并在项目中创建了多个类库。我想将所有模块加载到内核中。

为了加载所有模块,我在 MainViewModel 中使用了这段代码

public MainViewModel()
{
    IKernel kernel = new StandardKernel();
    kernel.Load(AppDomain.CurrentDomain.GetAssemblies());
    Plugins = kernel.GetAll<PluginBase>().ToList();
}

但不要在AppDomain.CurrentDomain.GetAssemblies() 中加载模块(插件)

【问题讨论】:

  • 好的。还有什么问题?
  • 不要加载我的模块。

标签: c# wpf ninject


【解决方案1】:

我使用此代码加载程序集。我找到了它there

var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
var loadedPaths = loadedAssemblies.Select(a => a.Location).ToArray();

var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));

【讨论】:

    猜你喜欢
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多