C#有哪些有名的依賴注入的框架?

主流的SSH到處都是依賴注入,另外獨立的依賴注入框架也數不過來,並有JSR-330作為規範。而C#這邊,似乎只有一個Unity,而且用的人似乎不多啊...

這是為什麼

補充:

@趙劼 問有沒有研究過,我確實沒有仔細研究過。我沒做過Java EE開發,但是Spring,Struts和Guice等框架確是如雷貫耳;C#這邊,名氣大的也就Unity了。

於是我把Java,C#,Spring,Structs,Guice,Unity關鍵字後面加上dependency injection,谷歌一下看結果數:

Java:1,100,000

C#:407,000

Spring:511,000

Struts:105,000

Guice:85,000

Unity:165,000

問題解決:

感謝@對數醬 的提示,從兩個語言的流行度上看,我給出的數據不能作為問題的依據,問題不成立。謝謝各位的回答。


問「為什麼」之前先問「是不是」系列。

前面有回答有頗完整的列表,但樓主搜索的時候沒搜到微軟自己出的Managed Extensibility Framework,比較不給力。

(不過MEF跟一般的IoC容器的功能相比,兩者有交集但並不等價就是了。MEF內置了一個IoC容器來實現可擴展性。)

另外:能搜出資料的條數,跟一個東西有多流行,兩者難說關聯性有多高。

嗯我想起一個黑Java的典型抖機靈就是拿Java的書跟別的語言X的書對比,Java一堆書 vs 語言X一本夠用的好書toka


dotnet/dotnet-developer-projects.md at master · Microsoft/dotnet · GitHub

  • Dependency Injection

    • Autofac - Autofac is an addictive Inversion of Control container for .NET 4.5, Silverlight 5, Windows Store apps, and Windows Phone 8 apps.
    • Castle Windsor - A mature Inversion of Control container available for .NET and Silverlight
    • DI Feature Tests - Tests that track commmon DI features among multiple containers
    • dI.Hook - DI container that allows invocation using AOP
    • DryIoc - DryIoc is small, fast, capable IoC Container for .NET
    • fFastInjector - fFastInjector is a high-performing dependency injector, service locator, and/or IOC (inversion of control) container.
    • Funq - A fast DI container you can understand.
    • Grace - Grace is a feature rich Dependency Injection container in a portable class library
    • Griffin - Inversion of control container with (almost) zero configuration
    • HaveBox - HaveBox is a very fast and lightweight IoC containter. The goal is to keep it fast and light, and at the same time easy to use.
    • Hiro - An ultra-lightweight, inversion of control container compiler framework
    • IfInjector - High performance mobile micro-IoC container.
    • LightCore - LightCore is a lightweight dependency injection container that can be used as a service locator and despite its simplicity and ease boasts numerous features.
    • LightInject - A ultra lightweight IoC container
    • MicroSliver - MicroSliver is a micro, non-bloat, non-intimidating and speedy .NET (ASP.NET, Silverlight, RIA Services, WPF, Forms and Metro!)
    • Mugen Injection - The MugeniInjection is a lightweight and fast managed IoC (Inversion of Control) and DI (Dependency Injection) with support for constructor, property and method call injection
    • Ninject for Desktop - Dependency injector for .NET
    • Ninject for Portable Class Libraries, Universal apps and Xamarin
    • QuickInject - QuickInject is a Unity 3.5 based IoC container that aims to give the Unity container a performance advantage in basic scenarios.
    • Simple Injector - Simple Injector is an easy-to-use Dependency Injection library for .NET 4+ that supports Silverlight 4+, Windows Phone 8, Windows 8 including Universal apps and Mono.
    • Spring.NET - Spring.NET is an open source application framework that makes building enterprise .NET applications easier.

    • StructureMap - StructureMap is a Dependency Injection / Inversion of Control tool for .Net that can be used to improve the architectural qualities of an object oriented system by reducing the mechanical costs of good design techniques.
    • StyleMVVM - Style MVVM is a toolkit designed for the Windows Store platform around the idea of being light weight and fast.
    • TinyIoC - An easy to use, hassle free, Inversion of Control Container for small projects, libraries and beginners alike.
    • Unity Container - The Unity Container (Unity) is a lightweight, extensible dependency injection container with optional support for instance and type interception.


樓主應該不是做.NET的…


推薦castle吧,castle涵蓋的方面很多,順著這條線能學到更多的東西,比如dynamicproxy


.net裡面到處都是依賴注入你竟然沒看到


因為你C#學的不好,看得太少想得太多。


autofac、ninject、unity

我的新公司還用一個叫lightinject的

新的http://asp.net vnext 自身就有依賴注入框架


原因有很多吧

例如依賴注入最初是在Java圈子裡發揚光大的,給大家一種Java的依賴注入是官方的感覺。所以你會有種學Java必須討論依賴注入的感覺,就像學.Net必須學習Entity Framework一樣。

還有就是Java生態系統里開源的東西比較多,開源一個特點就是重複造輪子。所以你有種Java圈子裡依賴注入的框架特別多的感覺。

最後就是Unity了,微軟出品,官方的。和Java喜歡找開源方案一樣,.Net圈子裡喜歡用微軟的東西,所以你會有種c#這邊只有Unity的感覺。


因為你對.net知之甚少,連簡單的搜索也不會做。

關於這個問題,可以參考此書:Manning: Dependency Injection in .NET

另外,作為一個一般性的原則:由於C#是一個更先進的語言,java能做的都可以做。


你考慮過使用Java和C#的總人數之間的差距嗎?


ninject, autofac, castle, unity


名氣大的絕對不只是unity啊,autofac和ninject基本天天用


目前正在用autofac,教程和例子都很完備,stackoverflow上面也有很多討論,建議一看。


推薦閱讀:

設計模式有何不妥,所謂的荼毒體現在哪?

TAG:Java | NET | C# | 設計模式 |