Loading unreferenced dll MVC Ninject
Asked Answered
M

2

0

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?

Monitor answered 16/7, 2013 at 9:59 Comment(2)
Why don't you add it as a project reference and Copy Local set to true? Either way, it's no doubt because the assembly isn't being deployed to the correct folder. Your deployment process needs to account for this.Taw
If i add a reference to the bindings project then the web project would indirectly reference every project which would mean that no other project could reference my web project due to circular referencing. Is this usual ?Monitor
J
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

Juglandaceous answered 16/7, 2013 at 10:3 Comment(2)
If i add a reference to the bindings project then the web project would indirectly reference every project which would mean that no other project could reference my web project due to circular referencing. Is this usual ?Monitor
It is, the web project is starting point, so web project should reference other projects not the other way. only in rear cases you need to reference web project, event in this cases it is usualy possible to refactor the code (by moving it in a separate assembly)so you don't have references to the web projectJuglandaceous
T
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.

Taw answered 16/7, 2013 at 10:23 Comment(0)
J
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

Juglandaceous answered 16/7, 2013 at 10:3 Comment(2)
If i add a reference to the bindings project then the web project would indirectly reference every project which would mean that no other project could reference my web project due to circular referencing. Is this usual ?Monitor
It is, the web project is starting point, so web project should reference other projects not the other way. only in rear cases you need to reference web project, event in this cases it is usualy possible to refactor the code (by moving it in a separate assembly)so you don't have references to the web projectJuglandaceous

© 2022 - 2024 — McMap. All rights reserved.