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?

TJF
  • 1,081
  • 1
  • 12
  • 26
  • 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. – Simon Whitehead Jul 16 '13 at 10:02
  • 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 ? – TJF Jul 16 '13 at 10:06

2 Answers2

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.

Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
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

Alexandr Mihalciuc
  • 2,537
  • 15
  • 12
  • 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 ? – TJF Jul 16 '13 at 10:06
  • 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 project – Alexandr Mihalciuc Jul 16 '13 at 10:10