gpt4 book ai didi

dependency-injection - 带有选定引号的控制反转与依赖注入(inject)——我的理解是否正确?

转载 作者:行者123 更新时间:2023-12-04 01:49:48 25 4
gpt4 key购买 nike

我已经阅读了许多解释 之间区别的线程。国际奥委会尽管许多解释相互矛盾,但我认为它们仍然帮助我理解了差异。
所以在这里我想问一下我的理解是否正确,并发布对我有帮助的摘录(尽管其中一些相互矛盾)。
我知道关于这个主题已经完成了很多线程,但我希望这个线程不会被关闭,因为我认为提到的线程中的任何 OP 都没有显示所有相关的帖子(来自各种线程)有帮助他们终于明白了。
无论如何,这是我的理解(如果可能,请单独解决/回答每个问题):
a) 当我们申请 直拨框架级别的原则,那么我们使用术语国际奥委会 ?以及实现的机制之一直拨在框架级别是 ?
b) 术语 国际奥委会当我们实现 时不适用直拨 (使用 DI )在较低级别/非框架级别,在这种情况下我们简称为 ?
c) 帮助我们实现直拨通过将依赖项的实际创建和选择的控制权传递给对所涉及的其他两个中立的第 3 方?
d) 当直拨在框架级别 (IoC) 应用(使用 DI ),然后反转三种类型的控制:

  • 界面的控制。 现在高层模块正在控制低层模块需要遵守的接口(interface),而不是相反
  • 流量的控制。 --> 现在框架代码(而不是用户/业务代码)控制程序的流程(换句话说 - 他们(即框架)调用你(即业务代码))
  • 依赖创建的控制 .这种反转将依赖项的实际创建和选择的控制权传递给第三方,该第三方对所涉及的其他 2 中的任何一方都是中立的。

  • e) 当 直拨在非框架级别应用(使用 DI ),然后反转两种类型的控制:
  • 界面的控制。 现在高层模块正在控制低层模块需要遵守的接口(interface),而不是相反
  • 依赖创建的控制 .这种反转将依赖项的实际创建和选择的控制权传递给第三方,该第三方对所涉及的其他 2 中的任何一方都是中立的。

  • ?
    以下是有帮助的摘录:
    Why so many terms to say the same thing? IoC and DIP

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

    ...

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

    ...

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


    Inversion of Control < Dependency Injection

    If you accept Fowler's definition, Inversion of Control is a muchbroader term than DI that covers allframework usage where you pluginto a framework, but the framework is still in control. DependencyInjection is a specialization of IoC that applies IoC specifically tomanage dependencies.


    Where exactly is the difference between IoC and DI

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

    ...

    In traditional applications, developers would write business code andframework code. The business code would then call the framework codeto accomplish tasks. Under an IoC model, you "invert" that model andcreate a framework that accepts business modules and calls them toaccomplish tasks

    Dependency Injection is a technique (hard to call it a pattern,really) of removing internal dependencies from implementations byallowing dependent objects to be injected into the class/method by anexternal caller. IoC frameworks use dependency injection to supplyuser modules and other dependent code to framework routines that "glueit all together." Dependency injection is used heavily by IoCframeworks because that is the mechanism that allows them to "CallYou."


    DIP vs. DI vs. IoC

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


    Does anyone have a good analogy for dependency injection?

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


    Difference between ioc and dependency injection

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


    Inversion of Control vs Dependency Injection

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


    谢谢你

    最佳答案

    好吧,这是我的观点:

    DI Overview

    直拨意味着您针对抽象进行编程。您将依赖类型从实现转换为抽象。

    国际奥委会意味着其他人负责获取给定抽象的实现。通常消费者会使用 关键字来获得依赖。使用 IoC,您可以反转控制,以便消费者不再负责创建实例。

    依赖注入(inject) 服务地点 的一部分控制反转 .
    DIvsSL

    另见:https://stackoverflow.com/a/10053413/175399

    关于dependency-injection - 带有选定引号的控制反转与依赖注入(inject)——我的理解是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11316688/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com