gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 17:42:08 24 4
gpt4 key购买 nike

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

Service Layer - ServiceModuleDataLayer - 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com