Loading unreferenced dll MVC Ninject

梦想的初衷 提交于 2019-12-11 21:19:35

问题


I have an MVC4 project in which I am using Ninject as the DI Framework. The problem I am having is trying to split my DI bindings from my implementation as i do not want my main web project to reference all of my other projects.

I have tried to create a separate project called Bindings which contains ninject modules:

public class WebModuleBindings : NinjectModule
{
    public override void Load()
    {
        Bind<IStaticDataRepository>().To<StaticDataRepository>();
    }
}

I then load this DLL dynamically in my web project:

    kernel.Load(bindingDll);

This works fine when i run it locally but when i use msbuild and deploy my application the bindings project dll is not included as it is not referenced anywhere.

What is the best way to solve this problem?


回答1:


Your web project is a host project. As a host project it is web project's responsibility to ensure that all dlls are provided. It would make a deployment easier




回答2:


There is no circular dependency when you have a Bootstrapper. Your flow of dependency would look something like this:

Web Project
    |
    |_______________- Bootstrapper project. All of your Ninject Bindings, etc.
    |                 The Kernel is also created here and passed back to the
    |                 Web project.
    |                                   |
    |                                   |
    ▼                                   |
Business Layer --------------------------
    |                                   |
    |                                   |
    |                                   |
    ▼                                   |
Data Access Layer -----------------------

                       Possibly a dangling Entities/POCO project here

Essentially, your bootstrapper is your composition root. It can reference every single other assembly so that it has access to all of the interfaces/concrete implementations it requires for bindings, etc. Then, your web project references both the Bootstrapper and the next layer down. This keeps your dependencies flowing down and can help structure your code a bit.



来源:https://stackoverflow.com/questions/17673518/loading-unreferenced-dll-mvc-ninject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!