What is the current state of IoC containers in .NE

2019-09-11 17:48发布

问题:

I know similar questions have been asked before

I'm looking to get the current state of IoC container framework in the .NET sphere.

Other questions on this topic are pretty dated. I'm prepping for a course on the subject, so I would like to present the most relevant information.

What currently is the best in IoC containers in .NET and why?
What is the most popular?

回答1:

No-one knows which DI Container is the most popular one, but here's a tip:

Compare download statistics on NuGet. All the major .NET containers are available through NuGet, so doing that will give you an idea about the relative popularity ranking between the containers.

Be aware that this method is problematic from a statistical viewpoint for a number of reasons:

  • There are other ways to download the containers. As an example, Unity also ships with Enterprise Library and can be downloaded from microsoft.com.
  • Downloads don't equal usage.
  • NuGet is (AFAIR) only available in Visual Studio 2010, so there may be a selection bias. Users of previous versions of Visual Studio may prefer different containers.

Despite the inaccuracy of the suggested comparison method, it's still the best that I'm aware of. Take it for what it is.



回答2:

I think Scott Hanselman's post from a couple of years ago is still relevant List of .NET Dependency Injection Containers (IOC)

Each of the container frameworks has added functionality and refined, all seem to support fluent interfaces now.

Personally I use Autofac

Nicholas Blumhardt has written a great article 'The Relationship Zoo' which describes in detail what you can do with Dependency Injection these days - well worth the read.