3

Possible Duplicate:
DAL -> BLL <- GUI + composition root. How to setup DI-bindings?

I'm defining a new solution and i've created some projects:

  • WebUI
  • Domain (contains my entities)
  • BusinessLayer (contains my business rules)
  • DataAccessLayer (contains my Abstract and Concrete implementations of my repositories)

Every project has a reference for my Domain.

In every example i see in Internet, the dependency injection (ninject) is defined in WebUI, but i cannot do that because it'll require me to add a reference for my DataAccessLayer.

If i move the binding association to the BusinessLayer then my WebUI will not become database agnostic because the bindings are hardcoded in my BusinessLayer.

Please give your opinion (even in the architecture), and why i'm having decision implementation problems?

thank U ALL

Community
  • 1
  • 1
TiagoDias
  • 1,785
  • 1
  • 16
  • 21

2 Answers2

2

You would normally configure the container in the application project. In your case the ASP.NET MVC application. This configuration will need to reference all assemblies in your solution. This is normally not a problem. Just don't use the DAL library from the rest of the web application.

If that is a problem for you, create a special Bootstrapper project that references all projects and configures the container. Then call that project from within your Application_Start event.

Steven
  • 166,672
  • 24
  • 332
  • 435
0

It's ok if you have references to your data access layer in web app, so long as you don't actually reference them in your code (other than in your ninject configuration). The reason is that Ninject is configured in code, thus to change your configuration you have to change the code.

If you want a purely file based configured approach, then you would need to use a different Container, or develop a file based configuration based on Ninject.

So long as your CODE is database agnostic, all you have to do is change your ninject code and modify the references and you're good to go, you don't have to change your app.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • Even when you use XML (file based) configuration, you will still have the references to the other projects and you even make it worse. Although the assemblies aren't referenced explicitly, they are still referenced (implicitly, but still referenced). It's the same, but now without compile time support :-) – Steven Nov 18 '11 at 22:50
  • 1
    @Steven - While that's true, the difference is that you can modify the data layer code without having to recompile your main app. Yes, the assemblies are still loaded regardless, but from a purely "Don't have to touch the code" approach, it's quite a bit different. – Erik Funkenbusch Nov 18 '11 at 23:43