Tuesday, March 15, 2011

Choosing a .Net Inversion of Control container for first attempt at Dependency Injection

Which IoC container is the easiest to get started with. This probably equates to which ones have the friendliest documentation. Not too worried about number of features.

From stackoverflow
  • I would start with the Smart Client Software Factory or Unity

    They include tons of samples, as well as the SCSF including some other design patterns to monkey with.

    Cameron MacFarland : Man do I have to disagree with you there. SCSF and it's ugly cousin CAB are some of the most poorly document and overly complicated frameworks that have come from the bowls of Microsoft. Them and the Enterprise Library have given me a very low opinion of the PnP group.
  • I like Castle Windsor and here you can find a three part article that describe all that you need to start. http://dotnetslackers.com/articles/designpatterns/InversionOfControlAndDependencyInjectionWithCastleWindsorContainerPart1.aspx

    StructureMap and Unity are also wel documented. BTW keep in mind that almost all the Containers works in the same way, so passing from one to another is quite simle.

  • What's easiest is pretty much dependent on where "you're coming from". But if you're familĂ­ar with the .Net 3.5 features such as lambdas and extension methods I'm a big fan of Autofac. Autofac makes heavy use of lambdas and extension methods for registering components instead of using xml-files. This adds the benefit that you have full type safety and also you get intellisence when registering. It's also a very lightweight container which I like.

    Autofac is hosted on Google code (http://code.google.com/p/autofac/) and has a pretty good Wiki with documentation.

  • Are you wanting to learn about IoC's?

    If so I recommend Oren Eini's IOC in 15 lines because nothing helps you learn faster than a really simple example with full source code.

  • I would recommend StructureMap.

    Very easy to set up and get you started.

    http://structuremap.sourceforge.net/Default.htm

  • Take a look at this DotNetRocks episode with James Kovacs: http://www.dotnetrocks.com/default.aspx?showNum=362

    And this DNRTV where he rolls his own IoC: http://www.dnrtv.com/default.aspx?showID=126

    Keith

    Dan Powley : Primarily the DNRTV episode answered my question, as at the end James Kovacs suggests that his SimpleDependencyResolver implementation can be swapped out for one of the more popular containers once you have need for more features.

0 comments:

Post a Comment