What should I consider when choosing a dependency injection framework for .NET?

see also What C # /. NET dependency Injection frameworks deserve attention in?

Now there are many dependency injection frameworks to choose from. Previously, you were often forced to use a specific dependency injection structure because of the library you used. However, the shared services locator library allowed the library code to be independent of injection frameworks.

The time required to learn all of them well enough to decide what to use is unreasonable. I do not believe that we have not reached the stage yet, that we can talk about a better structure of dependency injections. So, what questions should I ask about the project and about myself to help me choose the best dependency injection structure to use in this case?

It would also be useful to know why you are choosing the dependency injection infrastructure that you are currently using, and if you are still happy with this choice.

Is there any other useful dictionary to use when comparing dependency injection infrastructure styles?

Does the Locator service library work in real life or are you forced to use many different dependency injection programs in one project?

How easy is it to exaggerate your code with each concept of the Injection Framework, for example, tools like ReSharper work well with a given structure?

+28
dependency-injection inversion-of-control
Aug 12 '09 at 17:29
source share
4 answers

FYI, only this morning I found an interesting comparison between all .NET IoC containers:

http://elegantcode.com/2009/01/07/ioc-libraries-compared/

A few questions:

  • How much do you need basic support? Spring is probably the largest of them. Everyone used it or already heard about it, so much information. It also probably has the most features, but that means you just need to learn. A small container, such as Autofac, may be nice, but you may run into a problem that you won't find about.
  • Is w / Xml configuration convenient? Each IoC container is configuration and configuration dependent. Spring and Unity are heavy Xml.
  • Is this a permanent choice? If you are in one of those places where you get only one chance to choose, it does not matter. But, if you ever want to choose another solution in the future, you probably don't want an IoC that requires you to attribute your classes (sorta the reverse of the above question), because you will hate yourself when you need to tear it all all up. For comparison, wwapping from xml config may not be so painful.
  • What is your store? I had problems downloading several open source options just because of a "sigh! It's not Microsoft!" reactions. If you are a direct MS store, using Unity will be a much easier cultural victory.

In a personal note:

I used StructureMap for the same reasons that were mentioned in the blog I linked. I think the Xml config is a huge pain to support and, especially, debugging (see WCF). I have not tried Ninject yet, but based on their marketing, it should be super happy!

+15
Aug 12 '09 at 17:47
source share

It is hard to answer which structure is the β€œbest”, but I can tell you which structure is the simplest: a simple injector:

A simple injector is an easy to use inversion of the control library for .NET and Silverlight. It only supports code-based configuration and is an ideal starting point for developers unfamiliar with larger IoC / DI Libraries

http://simpleinjector.codeplex.com/

Shameless btw plug; -)

+6
Jan 06 '10 at 11:50
source share

I think that the choice comes down to finding a structure that meets your requirements, and then personal preferences.

Does your project use a library such as rhino tools that already integrate with the DI framework? If so, this might be a good starting point if you want to avoid using a β€œlot of different dependency injection frameworks.”

Check out these two posts:

  • SO: Unity vs Other IoC Containers corporate library
  • SO: What .NET injection injection environment are you using?
+2
Aug 12 '09 at 17:55
source share

Spring, and Unity are heavy Xml.

I would not agree with this statement for Unity; You can write

container.RegisterType<IRobot, MrRoboto>(); 

and do your customization in code using a free-style interface. Personally, I like Unity.

+2
Aug 23 '09 at 19:38
source share



All Articles