c# /。NET依赖注入框架值得一看? 你对它们的复杂性和速度有什么看法?
当前回答
编辑(不是作者写的):https://github.com/quozd/awesome-dotnet/blob/master/README.md#ioc:上有IoC框架的全面列表
Castle Windsor - Castle Windsor is best of breed, mature Inversion of Control container available for .NET and Silverlight Unity - Lightweight extensible dependency injection container with support for constructor, property, and method call injection Autofac - An addictive .NET IoC container DryIoc - Simple, fast all fully featured IoC container. Ninject - The ninja of .NET dependency injectors Spring.Net - Spring.NET is an open source application framework that makes building enterprise .NET applications easier Lamar - A fast IoC container heavily optimized for usage within ASP.NET Core and other .NET server side applications. LightInject - A ultra lightweight IoC container Simple Injector - Simple Injector is an easy-to-use Dependency Injection (DI) library for .NET 4+ that supports Silverlight 4+, Windows Phone 8, Windows 8 including Universal apps and Mono. Microsoft.Extensions.DependencyInjection - The default IoC container for ASP.NET Core applications. Scrutor - Assembly scanning extensions for Microsoft.Extensions.DependencyInjection. VS MEF - Managed Extensibility Framework (MEF) implementation used by Visual Studio. TinyIoC - An easy to use, hassle free, Inversion of Control Container for small projects, libraries and beginners alike. Stashbox - A lightweight, fast and portable dependency injection framework for .NET based solutions.
以下是原来的答案。
我想我在这里可能有点挑剔,但重要的是要注意DI(依赖注入)是一种编程模式,它由IoC(控制反转)框架促进,但并不需要。IoC框架只是让DI变得更容易,而且它们提供了许多其他优于DI的好处。
That being said, I'm sure that's what you were asking. About IoC Frameworks; I used to use Spring.Net and CastleWindsor a lot, but the real pain in the behind was all that pesky XML config you had to write! They're pretty much all moving this way now, so I have been using StructureMap for the last year or so, and since it has moved to a fluent config using strongly typed generics and a registry, my pain barrier in using IoC has dropped to below zero! I get an absolute kick out of knowing now that my IoC config is checked at compile-time (for the most part) and I have had nothing but joy with StructureMap and its speed. I won't say that the others were slow at runtime, but they were more difficult for me to setup and frustration often won the day.
更新
I've been using Ninject on my latest project and it has been an absolute pleasure to use. Words fail me a bit here, but (as we say in the UK) this framework is 'the Dogs'. I would highly recommend it for any green fields projects where you want to be up and running quickly. I got all I needed from a fantastic set of Ninject screencasts by Justin Etheredge. I can't see that retro-fitting Ninject into existing code being a problem at all, but then the same could be said of StructureMap in my experience. It'll be a tough choice going forward between those two, but I'd rather have competition than stagnation and there's a decent amount of healthy competition out there.
其他IoC视频也可以在Dimecasts上找到。
其他回答
我使用Simple Injector:
Simple Injector是一个简单、灵活、快速的依赖注入库,它使用最佳实践指导您的解决方案走向成功。
我用过Spring。NET,并取得了巨大的成功。我从未注意到它有任何实质性的开销,尽管我们使用它的项目本身相当繁重。只需要花一点时间阅读文档就可以设置它。
我花了大半天的时间苦苦挣扎,只为得到最简单的泉水。NET实例工作。永远不知道如何让它从XML文件中找到我的程序集。另一方面,在大约2小时内,我能够让Ninject工作,包括测试与NUnit和MSTest的集成。
Ninject很棒。看起来真的很快,但我没有做过任何比较。我知道作者Nate在Ninject和其他DI框架之间做了一些比较,并且正在寻找更多的方法来提高Ninject的速度。
我听很多我尊敬的人说过StructureMap和CastleWindsor的优点。在我看来,这是目前最值得关注的三大问题。
Autofac。https://github.com/autofac/Autofac它真的很快,很好。这里有一个比较链接(在Ninject修复内存泄漏问题后)。
http://www.codinginstinct.com/2008/05/ioc-container-benchmark-rerevisted.html
推荐文章
- Linq-to-Entities Join vs GroupJoin
- 为什么字符串类型的默认值是null而不是空字符串?
- 在list中获取不同值的列表
- 组合框:向项目添加文本和值(无绑定源)
- AutoMapper:“忽略剩下的?”
- 如何为ASP.net/C#应用程序配置文件值中的值添加&号
- 从System.Drawing.Bitmap中加载WPF BitmapImage
- 如何找出一个文件存在于c# / .NET?
- 为什么更快地检查字典是否包含键,而不是捕捉异常,以防它不?
- [DataContract]的命名空间
- string. isnullorempty (string) vs. string. isnullowhitespace (string)
- 完全外部连接
- 如何使用。net 4运行时运行PowerShell ?
- 在foreach循环中编辑字典值
- 如何在xml文档中引用泛型类和方法