其中,究竟是国际奥委会和DI之间的区别 [英] Where exactly is the difference between IoC and DI

查看:117
本文介绍了其中,究竟是国际奥委会和DI之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:结果
控制和LT反转;依赖注入






我总是读IOC(控制Inversin)和DI(依赖注射)在同样的情况下。是究竟IOC和DI之间的区别?如何从国际奥委会DI有什么不同?


解决方案

在常见的用法,术语已经变得有些代名词。国际奥委会最初的想法 - 控制反转 - 是有很大关系的好莱坞原则:不要打电话给我们,我们会打电话给您



在传统的应用程序,开发者可以编写业务代码和框架代码。那么企业代码将调用框架代码来完成任务。在一个IoC模式,你反转的模式,创建一个接受业务模块,并要求他们完成任务的框架。这一原则在多个开发框架,包括展出老的智能客户端软件工厂的和新的棱镜(或WPF / Silverlight的复合应用程序)的。在这些车型中,UI模块与IoC容器注册,并加载,需要根据配置和用户操作。虽然功能强大,这些模型也往往有一个非常陡峭的学习曲线。



依赖注入是一种技术(很难称之为一种模式,真)从内部的依赖通过允许依赖对象的实现,以由外部呼叫者被注入类/方法。国际奥委会框架使用依赖注入来提供用户模块和其他相关的代码框架例程胶水都在一起。

依赖注入大量使用的IoC框架,因为这是使他们能够在机制打电话给你。

IOC容器,比如温莎城堡和依赖结构图帮助注入提供了自动实例化和您注册类生命周期管理 - 包括自动实例化和以挂号类所需的参数注入。所有这一切都使得它更容易使用依赖注入,但不是必需的。



依赖注入是灵活的机制上的接口最大化的依赖,并降低对具体的实现依赖。因此,使用依赖注入系统可以支持能够根据情况使用可插拔实现类。这个可插拔的一个非常大的好处是,它使创建单元测试更容易。你可以嘲笑的对象所需的接口,然后将其注入你的测试对象。<​​/ p>

所以,国际奥委会是真正的更广泛的原则和DI是内部的基本技术。 IOC(好莱坞原则)系统往往是非常复杂的,可能很难理解,因而有陡峭的学习曲线。 DI,而另一方面对于日常开发一个很好的做法。我倾向于选择理解和明确了冷静,但复杂的。


Possible Duplicate:
Inversion of Control < Dependency Injection

I always read IoC(Inversin of Control) and DI(Dependency Injection) in the same context. What is exactly the difference between IoC and DI? How does IoC differ from DI?

解决方案

In common usage, the terms have become somewhat synonymous. The original idea of IoC -- Inversion of Control -- was very much related to the "Hollywood Principle:" Don't Call Us, We'll Call You.

In traditional applications, developers would write business code and framework code. The business code would then call the framework code to accomplish tasks. Under an IoC model, you "invert" that model and create a framework that accepts business modules and calls them to accomplish tasks. This principle is exhibited in several development frameworks including the old Smart Client Software Factory and the newer Prism (or Composite Applications for WPF/Silverlight). In these models, the UI Modules are registered with an IoC Container and loaded as needed based on configuration and user actions. While powerful, these models also tend to have a very steep learning curve.

Dependency Injection is a technique (hard to call it a pattern, really) of removing internal dependencies from implementations by allowing dependent objects to be injected into the class/method by an external caller. IoC frameworks use dependency injection to supply user modules and other dependent code to framework routines that "glue it all together." Dependency injection is used heavily by IoC frameworks because that is the mechanism that allows them to "Call You."

IoC Containers, such as Castle Windsor and Structure Map help with dependency injection by providing automatic instantiation and lifecycle management of classes you register -- including automatic instantiation and injection of parameters required by registered classes. All of this makes it easier to use dependency injection, but is not required.

Dependency Injection is a mechanism for flexibility that maximizes dependency on Interfaces while minimizing dependency on specific implementation. Consequently, systems that use dependency injection can support "pluggable" implementation classes that can be used depending on circumstances. A very big benefit of this "pluggability" is that it makes creating Unit Tests much easier. You can mock an object to the needed interface, then inject it into your test object.

So, IoC is really the broader principle and DI is a fundamental technique within. IoC (Hollywood Principle) systems tend to be pretty complex, can be hard to understand, and thus have steep learning curves. DI, on the other hand is a good practice for everyday developers. I tend to prefer understandable and clear over cool, but complex.

这篇关于其中,究竟是国际奥委会和DI之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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