哪些 .NET 依赖注入框架值得研究? [英] Which .NET Dependency Injection frameworks are worth looking into?

查看:29
本文介绍了哪些 .NET 依赖注入框架值得研究?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些 C#/.NET 依赖注入框架值得研究?您对它们的复杂性和速度有何看法.

Which C#/.NET Dependency Injection frameworks are worth looking into? And what can you say about their complexity and speed.

推荐答案

edit(非作者提供):https://github.com/quozd/awesome-dotnet/blob/master/README.md#ioc:

  • Castle Windsor - Castle Windsor 是同类最佳、成熟的控制反转容器,可用于 .NET 和银光
  • Unity - 轻量级的可扩展依赖注入容器,支持构造函数、属性和方法调用注入莉>
  • Autofac - 一个令人上瘾的 .NET IoC 容器
  • DryIoc - 简单、快速、功能齐全的 IoC 容器.
  • Ninject - .NET 依赖注入器的忍者
  • StructureMap - .Net 的原始 IoC/DI 容器
  • Spring.Net - Spring.NET 是一个开源应用程序框架,它使构建企业 .NET 应用程序更容易
  • LightInject - 超轻量级 IoC 容器
  • Simple Injector - Simple Injector 是一个易于使用的依赖注入 (DI) 库,适用于 .NET 4+,支持 Silverlight 4+、Windows Phone 8、Windows 8,包括通用应用和 Mono.
  • Microsoft.Extensions.DependencyInjection - ASP.NET Core 应用程序的默认 IoC 容器.
  • Scrutor - Microsoft.Extensions.DependencyInjection 的程序集扫描扩展.
  • VS MEF - Visual Studio 使用的托管扩展框架 (MEF) 实现.
  • TinyIoC - 一个易于使用、无忧的控制反转容器,适用于小型项目、图书馆和初学者一样.
  • 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
  • StructureMap - The original IoC/DI Container for .Net
  • Spring.Net - Spring.NET is an open source application framework that makes building enterprise .NET applications easier
  • 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.

原始答案如下.

我想我在这里可能有点挑剔,但重要的是要注意 DI(依赖注入)是一种编程模式,由 IoC(控制反转)框架促进,但不需要.IoC 框架只是让 DI 变得更加容易,并且它们提供了许多超越 DI 的其他好处.

I suppose I might be being a bit picky here but it's important to note that DI (Dependency Injection) is a programming pattern and is facilitated by, but does not require, an IoC (Inversion of Control) framework. IoC frameworks just make DI much easier and they provide a host of other benefits over and above DI.

话虽如此,我确定这就是您要问的.关于 IoC 框架;我曾经使用 Spring.NetCastleWindsor 很多,但背后真正的痛苦是您必须编写的所有讨厌的 XML 配置!他们现在几乎都在朝这个方向发展,所以我在过去一年左右的时间里一直在使用 StructureMap,并且由于它已经使用强类型泛型和注册表移动到流畅的配置,我在使用 IoC 时的痛苦障碍已降至零以下!现在我知道我的 IoC 配置是在编译时检查的(大部分情况下),我感到非常兴奋,而且我对 StructureMap 及其速度感到非常满意.我不会说其他的在运行时很慢,但它们对我来说更难设置,而且经常受挫.

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.

更新

我在我的最新项目中一直使用 Ninject,使用起来非常愉快.词在这里有点让我失望,但是(正如我们在英国所说)这个框架是狗".我强烈推荐它用于您想要快速启动和运行的任何绿色领域项目.我从 Justin Etheredge 的 精彩的 Ninject 截屏视频 中得到了我需要的一切.我看不出将 Ninject 改装到现有代码中是一个问题,但是对于 StructureMap 也可以这样说 以我的经验.在这两者之间前进将是一个艰难的选择,但我宁愿有竞争也不愿停滞不前,而且那里有相当多的良性竞争.

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.

还可以在此处在 Dimecasts 上找到其他 IoC 截屏视频.

这篇关于哪些 .NET 依赖注入框架值得研究?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆