开发者

C# Dependency Injection frameworks [duplicate]

开发者 https://www.devze.com 2023-02-14 08:15 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Which .NET Dependency Injection frameworks are worth looking into?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Which .NET Dependency Injection frameworks are worth looking into?

Hi,

As a new kid in the C#/.NET block just moved in from Java neighbourhood, I am looking for options in Dependency Injection/IoC frameworks for .NET/C#.

From Scott Hanselman's blog post few years ago I got a fairly long list of DI frameworks, but there was really not enough information to go with beyond the list itself (plus a license and a version number) to make any semi-intelligent choice. Nor have I developed a ghestalt of the relative popularity (and thus the community support available) for any of these. And the list itself dates from 2008, which makes it a bit outdated, so I would like to ask kindly SO community for help on this matter.

Please list (or vote for) your favourite DI framework, adding a link to framework off开发者_运维百科icial website and please be so kind as to provide some reasoning for helping me and others developers like me to make a choice.

A code sample snippets for declaring and injecting dependencies would be of great help as well.

NB: Please restrict yourselves to one entry per response please, to keep it simple and objective.


I have used Ninject before and got on well with it. There are code samples on the front page of the website.

http://ninject.org/

Edit: Ninject also supports MVC


Of those I have tried, I like Unity best by far. Easy to use, and feature rich. A note is that it's not supported if you are developing for Windows Phone 7.


Of the list I've tried Unity, StructureMap and Autofac.

I perfer StructureMap, I think it's the most straightforward and easiest to use. (didn't spend much time with Autofac tho since was just messing in my own time)


You could also use MEF, but be aware that MEF is not only for this purpose. Mostly MEF is a little oversized for normal DI scenarios, but very usefull if you intent to develop a extendible app.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号