0

I need to implement DI in my Web App. This is not just the web app but the supporting business layer classes (separate project) and data access layer classes (separate project). What is the best tool to use for this, I know there is something inbuilt into MVC but my business logic layer and data access layer is not using MVC.

user3547774
  • 1,621
  • 3
  • 20
  • 46

2 Answers2

2

First, I suggest that you should read more about Dependency Injection. It's not a framework (although there are Dependency Injection frameworks), it's a design pattern. You can implement DI without any kind of framework. The framework just gives you more functionality.

Second, MVC does not provide a DI framework, although it does have hooks to bring a framework into MVC.

Third, Dependency injection frameworks are configured at the application level (in your case MVC). It doesn't matter that your business and data layers are separate projects, they're still used by your application layer, and the application layer is the one that has to have the DI framework because all objects are created from there (this is called the composition root).

You can use any DI framework you want. There is no "best tool". They all do the same thing, they just do it in different ways, so it boils down to personal preference.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
1

I completely agree with Erik Funkenbusch on this. DI is not a tool and you should start out by applying patterns, not using a tool. If you start using a tool without applying the patterns, you'll be in worse place than you started.

That said, for .NET there are many DI containers, but the top 6 are:

  1. Autofac
  2. Ninject
  3. Castle Windsor
  4. Unity
  5. StructureMap
  6. Simple Injector

But there are many more as you can see on this list for instance.

Steven
  • 166,672
  • 24
  • 332
  • 435
  • Thanks, I know I need to design it first, all I wanted was a tool that will help me implement the design. – user3547774 Jul 16 '14 at 10:02
  • 1
    @user3547774: The tool will NOT help to implement the design. Only YOU can implement the design. The tool will only help in keeping your Composition Root maintainable, but can ONLY do this when you designed your application according to the SOLID principles. – Steven Jul 16 '14 at 10:11