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

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

问题描述

哪些C#/ .NET依赖注入框架值得研究?
你可以谈谈他们的复杂性和速度。

解决方案

我想我可能在这里有点挑剔但重要的是要注意,DI(依赖注入)是一种编程模式,由IoC(控制反转)框架来实现,但并不需要。 IoC框架使DI变得更加容易,除了DI之外,它们还提供了许多其他优点。



据说,我确信这是你所要求的。关于IoC框架我曾经使用 Spring.Net CastleWindsor 很多,但真正的痛苦在于后面的是所有那些讨厌的XML配置你必须写的!现在他们几乎都是这样移动的,所以我一直在使用 StructureMap ,并且由于它已经转移到使用强类型的泛型和注册表的流畅配置,我使用IoC的痛苦障碍已经下降到零以下!我知道现在我的IoC配置是在编译时检查的(绝大部分),我已经没有什么喜欢与StructureMap和它的速度。我不会说其他人在运行时缓慢,但是我们更难以设置和挫败经常赢得当天。



更新



我最近一直在使用 Ninject 项目,一直是绝对的乐趣使用。这句话让我失望,但是(正如我们在英国所说的那样),这个框架是狗。我强烈建议您在任何需要快速启动和运行的绿地项目中。 Justin Etheredge的一系列Ninject截图,我得到了所有需要的东西。我看不出将现有代码中的修改后的Ninject成为一个问题,但是可以这样说: StructureMap 在我的经验在这两者之间,这将是一个艰难的选择,但我宁愿比赛停滞不前,还有一个体面的健康竞争。



其他IoC也可以在这里的Dimecast 找到截屏。


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

解决方案

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.

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.

Update

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.

Other IoC screencasts can also be found here on Dimecasts.

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

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