NInject可以按需装载模块/组件吗? [英] Can NInject load modules/assemblies on demand?

查看:79
本文介绍了NInject可以按需装载模块/组件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NInject中是否有设施可以像在Unity中一样按需从其他模块(程序集)加载服务?

Are there facilities in NInject that will allow me to load services from other modules (assemblies) on demand like it's done in Unity?

推荐答案

我很确定这是您要查找的内容:

I'm pretty sure this is what you're looking for:

var kernel = new StandardKernel();
kernel.Load( Assembly.Load("yourpath_to_assembly.dll");

如果您在Ninject.dll中查看带有反射器的KernelBase,您将看到此调用将以递归方式加载已加载的程序集中的所有模块(Load方法采用IEnumerable)

If you look at KernelBase with reflector in Ninject.dll you will see that this call will recursively load all modules in the loaded assemblies (Load method takes an IEnumerable)

public void Load(IEnumerable<Assembly> assemblies)
{
    foreach (Assembly assembly in assemblies)
    {
        this.Load(assembly.GetNinjectModules());
    }
}

这篇关于NInject可以按需装载模块/组件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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