控制反转依赖注入 [英] Inversion of Control < Dependency Injection

查看:17
本文介绍了控制反转依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感觉没有控制反转这样的东西,或者更确切地说,正确的术语是依赖注入.我这样假设有错吗?

I'm getting the feeling that there's is not such thing as inversion of control or rather the correct term is dependency injection. Am I wrong to assume this?

为了我自己,我一直在尝试定义 IoC.在这样做的过程中,我学到了很多关于 IoC 容器和依赖注入的知识.

I've been trying to define IoC for my own sake. In doing so I've learned a great deal about IoC containers and dependency injection.

刚才,我从 Martin Fowler 的网站上读到了这个:

Just now, I read this from Martin Fowler's website:

因此,我认为我们需要更多此模式的特定名称.控制反转太笼统了术语,因此人们发现它令人困惑.结果有很多与各种国际奥委会倡导者的讨论我们选择了依赖这个名字注射.

As a result I think we need a more specific name for this pattern. Inversion of Control is too generic a term, and thus people find it confusing. As a result with a lot of discussion with various IoC advocates we settled on the name Dependency Injection.

在现代 IoC 的世界中,依赖注入不只是实现 IoC 的一种方式吗?

In the world of modern IoC isn't dependency injection just one way to achieve IoC?

推荐答案

如果你接受 Fowler 的定义,控制反转是一个比 DI 更更广泛的术语,它涵盖了所有框架用法,其中您插入到框架中,但框架仍处于控制之中.

If you accept Fowler's definition, Inversion of Control is a much broader term than DI that covers all framework usage where you plug into a framework, but the framework is still in control.

例如,在 .NET 中,ASP.NET 或 Windows Presentation Foundation 等框架最终处于控制之中,但提供了各种事件接缝可用于构建一个应用程序.在其他平台上也是如此.

For example, in .NET, frameworks such as ASP.NET or Windows Presentation Foundation are ultimately in control, but provide various events and Seams you can use to build an application. The same is true on other platforms.

依赖注入是 IoC 的一个专业化,它专门应用 IoC 来管理依赖项.

Dependency Injection is a specialization of IoC that applies IoC specifically to manage dependencies.

这篇关于控制反转依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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