为什么人们谈论 DI 框架“实例化对象图”?而不是“实例化对象”?
我正在读一本关于 DI 的书,里面总是谈论 DI 框架“实例化对象图”。为什么这样说而不是“实例化对象”?
I'm reading a book about DI that always talks about DI frameworks "instantiating an object graph". Why say it this way rather than "instantiating objects"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对象图由持有彼此引用的对象组成。在这种情况下,图的另一个名称是网络。
如果 IOC 系统忘记设置对象之间的引用,那么它就没有多大用处! IOC 系统的全部价值在于对象自动获取它们所需的其他对象的引用的方式。
A graph of objects consists of objects that hold references to each other. Another name for a graph in this context is a network.
An IOC system wouldn't be much use if it forgot to set up the references between the objects! It's the way the objects automatically get references to other objects they need that is the whole value of an IOC system.
术语“对象图”意味着您有一组将同时创建的对象。使用此术语可以帮助区分依赖注入模式(您通常仅在单个位置引用 DI 框架)和服务定位器模式(您将在其中引用使用它在整个应用程序的多个位置创建/访问对象)。
The term "object graph" implies that you have a set of objects that will be created at the same time. Using this term can help distinguish between the Dependency Injection pattern (where you will usually only refer to the DI framework in a single place) and the Service Locator pattern (where you will use it to create/access objects in multiple places throughout your application).
图是一组互连的对象。因此,它的实例化可以代表几个单独对象的实例化。
为了区分单个对象的创建和一组对象的创建,我们使用术语“对象图”。它有助于传达
Resolve
操作的范围。A graph is a set of interconnected objects. Thus, its instantiation may represent the instantiation of several individual objects.
To distinguish the creation of a single object from the creation of a set of objects, we use the term "object graph". It helps to communicate the scope of the
Resolve
operation.