Question

What Inversion of Control Container framework would you recommend to a beginner in this area?

Was it helpful?

Solution

James Kovacs did a dnrtv screencast where he shows how to create your own IOC container. I recommend this to a beginner not because it's necessarily the one you want to use but because it shows the basics of why you need an IOC container and what the basic functionality is. After this, try moving on to Castle Windsor or Structure Map.

OTHER TIPS

Autofac.

Lightweight, simple, fast, C# 3.0-oriented and works (for me) better in complex projects than any other IoC Container (even Windsor).

Primary features:

  • Deterministic disposal of components
  • Expression-based configuration
  • Proper support for multi-scoped component resolution
  • High performance
  • Lean codebase

I recall there are some really simple tutorials from BitterCoder on Castle's Windsor which I found helpful and easy to follow.

Even if you decide to use Windsor or not, those walkthroughs should still give you a good idea of the types of features / functionality to expect from other containers.

There is a great book out by Mark Seemann called Dependency Injection In .Net. The latter half of the book covers 6 popular frameworks in enough detail to get a feel for them. It's worth a look to help a new person decide. He also covers poor man's dependency injection for those not ready to try a container, but want to at least write their application in a manner that can easily be converted to use an IoC container.

The containers he covers are:

Danial Cazzulino has a bunch (scrunch?) of screencasts on creating the Funq DI Container. Funq is lightweight and fast but lacks some of the bells and whistles of the larger, more established frameworks.

I use the Funq-derived Munq which is also lightweight and fast and is a simple way to add a DI Container to MVC3 projects via Nuget. Up to now I haven't found any need to move to a different framework - Munq has been very adequate.

I have done some evaluation of the Spring.NET port. It offers AOP, config-file setup of the container, and other cool stuff. I think their site is well organized and the docs are well written.

I would say StructureMap. It is one of the more mature framework and really easy to use. Moreover it can integrate well with NMock to create mock objects which are invaluable for unit testing. The Microsoft supported framework is Unity so you may look at that as well.

I agree with dp. The author of that screencast even says that you should roll your. This is so you will know how they work. Then once you have that down you can move on to the more full featured one's.

It has also been mentioned that there really isn't that a 'one IOC container to rule them all'. This is because they pretty much all have the same features. It comes down to which implementation you favor. For instance, if you are using the Enterprise Library Framework then heavily then you might favor the Unity container because you get free tie-ins to the rest of EntLib. Or maybe you are allergic to XML then you can use Ninject which has a very nice fluent interface. Each framework has its strengths and weaknesses but they will pretty much be the same from the beginners stand point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top