c# - 如何将 NInject 模块链接在一起

标签 c# asp.net dependency-injection ninject

我有一个多层应用程序,它使用 NInject 解决依赖注入(inject)问题。每层都有一个特定的 NInject 模块:

Service Layer - ServiceModule
DataLayer - DataModule

In my presentation layer I really dont want to load every single module. Instead of that I want, for an example, load the ServiceModule and the module is responsible to load its dependencies.

How can I achieve that?

For example here is my ServiceModule:

public class ServicesModule : NinjectModule
{
    public override void Load()
    {
        ...
        Bind<IProductService>().To<ProductService>();
        ...
    }
}

最佳答案

很简单,在 NInject 模块中您可以访问内核:

Kernel.Load(new [] { new [YourModule]() });

关于c# - 如何将 NInject 模块链接在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14525601/

相关文章:

c# - 流畅的断言 Should().ThrowExactlyAsync 应该对于派生类型失败,但它不会

c# - ASP.NET MVC 路由和 Html.ActionLink

javascript - 使用 Jquery 序列化一个 javascript 数组

php - 在自定义用户模块中扩展 ZfcUser 的 UserController

c# - OutOfMemoryException 与 gcAllowVeryLargeObjects

c# - 包装函数的属性?

c# - 为什么在 get 方法之前需要 IEnumerable<string> ?

asp.net - ASP.NET 中的 session 超时

javascript - Angular UI Router - 子状态的解析始终等待父状态解析

c# - 如何使用依赖注入(inject)在运行时创建新对象