使用选定引号反转控制与依赖注入 – 我的理解是否正确?

Inversion Of Control vs Dependency Injection with selected quotes – is my understanding correct?

我读过很多文章来解释IOC和DI之间的区别,虽然许多解释相互矛盾,但我认为它们仍然帮助我理解区别。

所以在这里我想问一下我的理解是否正确,还有一些摘录对我有帮助(尽管其中有些内容相互矛盾)。

我知道有很多关于这个主题的线程,但是我希望这个线程不会被关闭,因为我不认为上面提到的线程中的任何一个操作也显示了所有相关的帖子(来自不同的线程),帮助他们最终理解它。

无论如何,我是这样理解的(如果可能,请单独回答每个问题):

a)当我们在框架级别应用DIP原则时,我们使用"IOC"?在框架级别实现DIP的机制之一是DI?

b)当我们在较低级别/非框架级别执行DIP(使用DI)时,IOC一词不适用,在这种情况下,我们简单地称之为DI?

c)DI通过将依赖关系的实际创建和选择的控制权传递给第三方来帮助我们实现DIP,第三方与其他2个相关方中的任何一个都是中立的?

d)当在框架级别(IOC)应用DIP时(使用DI),则三种控制类型将被反转:

  • 接口的控制。现在高级模块正在控制下级模块需要遵守的接口,而不是相反的方式。

  • 流量的控制。>现在,框架代码(而不是用户/业务代码)控制程序的流程(换句话说,它们(即框架)调用您(即业务代码))。

  • 依赖项创建的控制。此反转将对依赖项的实际创建和选择的控制权传递给第三方,第三方与其他2个相关方中的任何一个保持中立。

  • e)当在非框架级别应用DIP(使用DI)时,两种类型的控制反转:

  • 接口的控制。现在高级模块正在控制低级模块需要遵循的接口,而不是相反的方式。

  • 依赖项创建的控制。此反转将对依赖项的实际创建和选择的控制权传递给第三方,第三方与其他2个相关方中的任何一个保持中立。

  • 以下是一些有帮助的摘录:

    为什么有那么多的条件说同样的话?国际奥委会与浸染

    Inversion of Control is the generic term. Dependency Injection is a
    specific type of IoC

    ...

    Inversion of Control is when the framework/infrastructure invokes
    application code, rather than the other way around

    ...

    can do DI without doing IoC. If you inject aConsoleStringWriter into a
    HelloWorld I don't really think of this as IoC because there is no
    "framework" or"infrastructure".

    控制反转<依赖注入

    If you accept Fowler's definition, Inversion of Control is a much
    broader term than DI that covers allframework usage where you plug
    into a framework, but the framework is still in control. Dependency
    Injection is a specialization of IoC that applies IoC specifically to
    manage dependencies.

    国际奥委会和DI的区别在哪里

    IoC is the ability to vary the implementation of a contract. DI is the
    ability to supply the implementation.

    ...

    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

    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."

    DIP与DI与IOC

    DIP is the principle that guides us towards DI. Basically, loose
    coupling is the goal, and there are at least two ways to achieve it.
    ? Dependency Injection ? Service Locator

    有人对依赖注入有很好的类比吗?

    The essence of Inversion of Control (of which Dependency Injection is
    an implementation) is the separation of the use of an object from the
    management thereof.

    IOC和依赖注入的区别

    The terms Dependency Injection (DI) & Inversion of Control (IoC) are
    generally used interchangeably to describe the same design pattern
    (although not everyone agrees on that point, and some people tend to
    apply them in slightly different ways). The pattern was originally
    called IoC, but Martin Fowler proposed the shift to DI because all
    frameworks invert control in some way and he wanted to be more
    specific about which aspect of control was being inverted.

    控制反转与依赖注入

    Inversion of Control (IoC) means that objects do not create other
    objects on which they rely to do their work. Instead, they get the
    objects that they need from an outside source (for example, an xml
    configuration file). Dependency Injection (DI) means that this is done
    without the object intervention, usually by a framework component that
    passes constructor parameters and set properties.

    谢谢您


    这就是我的观点:

    DI Overview

    DIP意味着你的程序是针对抽象的。您将依赖关系的类型从实现转换为抽象。

    IOC意味着其他人负责获取给定抽象的实现。通常,消费者会使用新关键字获取依赖项。在IOC中,您颠倒了控制权,这样消费者就不再负责创建实例了。

    依赖注入和服务位置是控制反转的一部分。DIvsSL

    另请参阅:https://stackoverflow.com/a/10053413/175399


    我在我的[博客]:http://dotnet-stuff.com/tutorials/dependency-injection/dependency-inversion-principle-dependency-injection-and-inversion-of-control-dip-ioc-and-di上写下了不同之处:"单击此处获取更新",我们如何组织控制反转、依赖反转原则和依赖注入。简而言之,我们可以这么说--

    在顶部是依赖反转原理,这是软件设计的一种方式。它没有说明如何制作独立的模块。控制反转(IOC)为应用DPI原理提供了途径。但国际奥委会仍然没有提供具体的实施方案。它给出了一些方法,以便我们可以反转控件。如果我们想使用绑定反转或依赖创建来反转控制,那么我们可以通过实现依赖注入(DI)来实现它。