I am looking for a simple yet practical and robust IOC/DI framework for .net?

The great thing about proper use of DI is that you can defer the decision about which DI Container to use until the last responsible moment In application architecture terms, this corresponds to a so-called Composition Root which is where you wire all depedendencies together. This is often the application's entry point.

The great thing about proper use of DI is that you can defer the decision about which DI Container to use until the last responsible moment. In application architecture terms, this corresponds to a so-called Composition Root, which is where you wire all depedendencies together. This is often the application's entry point.

Apart from the Composition Root, the entire application can be written without referencing any particular DI Container at all. You just need to follow well-known patterns and principles. When it comes to pick a DI Container, I'm aware of these DI Containers for .

NET: Castle Windsor StructureMap Unity Autofac Ninject Spring. NET Personally, I have been happy with Castle Windsor so far, but I have yet to gain extensive experience with all of these containers.

This is not entirely true. Various containers offer varying capabilities, and approach different problems from different angle. You can take advantage of powerful capabilities of container you choose (like startability, event wiring, typed factories etc) without referencing it, but by designing your components in a certain way.

You can often adapt other container to work with your components, but it means you'd need to write some additional glue code to make up for its deficiencies/differences. – Krzysztof Koźmic Feb 26 '10 at 9:03 But that is how I write code :) – Mark Seemann Feb 26 '10 at 9:29.

Here's an ASP. NET (not MVC) Ninject sample: davidhayden.com/blog/dave/archive/2008/0....

I have used ninject and found it easy to bring new developers up to speed with it.

Consider to start with wiring by hand: see blog.objectmentor.com/articles/2010/01/1... . It gives less-experienced developers a better insight in the basics of IOC/DI.

I think you are being too hasty to reject spring.net. Spring offers an extremely flexible learning curve, so at the beginning it's kind of "you take what you want from it" approach. You can start with the simplest-of-all IoC container, and later on move to aop, transactions, unit testing, or whatever you desire, so the complexity builds up gradually.

This was the #1 selling point at my last two jobs for using Spring. Additional points were: It doesn't force you to use its api or to bend your architecture. Again, this leads you to adapt its features at your own pace.

Very extensive documentation. When the project matures, so will your developers, so spring will come out handy at the end ... (at no cost in the beginning, in my opinion).

Autofac is my container of choice. It allows registration via lambda expressions for maximum flexibility (the link has some nice examples). It also has a Silverlight-compatible version.

I'm unsure if the other containers do. As for placement, the container should be built during application startup. For an ASP.NET application, this would be in the Global.

Application_Start method. Autofac has ASP.NET integration which injects pages instances using the container you build during startup.

1 Castle Windsor has a Silverlight 3 version – Mauricio Scheffer Feb 4 '10 at 3:59.

Have a look at funq.codeplex.com/ first of all it's extremely fast compared to windsor and other reflection based containers second of all it's very flexible but still has a very readable configuration (If you've gotten your head around Lamba expressions which should take to long any ways).

2 it provides close to no out of the box functionality. It's a scaffolding on which you need to write your entire wiring up manually. – Krzysztof Koźmic Feb 26 '10 at 9:04 I agree with Krzysztof: For instance, Funq doesn't support automatic constructor injection (auto-wiring), which makes even the simplest registration cumbersome and brittle.

You'll end up changing your DI configuration after the simplest little change. – Steven May 4 at 7:24 @Steven Yes nothing is done for you (and the project is now laid dormant) I however disagree with the brittle part. It's type safe which as far as I remember it was the only one to accomplish when I wrote my answer.

If there's no need to be able to change the configuration runtime I believe the configuration should be type safe. I'd rather have a compile error than a runtime error (which would be the case with windsor if you're not using autowiring or have forgotten to define the needed concrete classes) – Rune FS May 4 at 12:35 Most containers allow you to register delegates, so it's not a feature exclusive to Funq. I understand you love compile-time checking: I do too.

With delegates however, it's still as easy as with auto-wiring to create a configuration that compiles but fails at runtime (you just have to forget to register a single dependency). Because of that, I can't see the lack of auto-wiring as a strength. Much more useful would be a feature that allows you to verify the container, once you're done configuring.

For instance, Simple Injector contains a Verify() method that does exactly this. – Steven May 4 at 13:13.

We use the managed extensibility framework. It is part of the . NET 4.0 framework (currently in release candidate), where you can find it in the System.ComponentModel.

Composition namespace. The codeplex site is currently still the best source of documentation. The focus of MEF is more on "extensibility" rather than "dependency injection", but it uses dependency injection to achieve this.

For example, the visual studio 2010 code editor uses MEF to enable extensibility. We use it as a DI framework and have not yet run into any problems (though I did need the dynamic instantiation sample which is not part of the core yet).

If you're yet familiar with any DI framework, I'd go with the Simple Injector. It has a very simple API, that will get you started very quickly. Although simple, it still enables many advanced configuration scenario's.

The library designed with migration in mind, which means that switching to another framework would is rather straightforward. To prove this point, there is an migration guide on the project's wiki.

In addition to Ninject, which is a great product, there are also two other options that I'm familiar with: Microsoft's Unity. Some Alt. NET folks think it's a little on the big & complicated side.

I've been using it for several months now as part of Prism (Prism is NOT required to use Unity. It's available stand-alone) and I've found it to be simple and straight-forward. StructureMap.

I've found StructureMap to also have a very gentle learning curve with fast ramp up. Hope this helps.

I find StructureMap very usefull and intuitive to use. I played with Ninject a bit and found that less convenient, but YMMV. I would also recommend you use the common service locator as an intermediary between the actual implementation of your IOC and your application.

When you want to switch your IOC/DI container later on, this is less painfull. There are adapters for StructureMap and Castle windsor. And I think from googling that there also is an adapter for Ninject 2 according to this blog.

4 Being container-agnostic has little to do with the CommonServiceLocator. If you write your code in dependency-injection style you don't need to reference your container or the CommonServiceLocator. – Mauricio Scheffer Feb 3 '10 at 19:07 See commonservicelocator.codeplex.Com/… stackoverflow.

Com/questions/735712/… – Mauricio Scheffer Feb 3 '10 at 19:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions