有什么区别&QUOT真正的区别;庶子注塑和QUOT;和"穷人的注塑和QUOT; [英] What is the real difference between "Bastard Injection" and "Poor Man's Injection"

查看:141
本文介绍了有什么区别&QUOT真正的区别;庶子注塑和QUOT;和"穷人的注塑和QUOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这本书中的使用.NET依赖注入我知道,对象图应该在组成的根,这使得有很大的意义对我来说,当你使用一个IoC的应用程序创建容器。

From the "Dependency Injection in .Net" book I know that the object graph should be created at the Composition Root of the application which makes a lot of sense to me when you are using an IoC container.

在正在取得使用DI的尝试时,我见过的所有应用程序,总有两个构造函数:一个与依赖作为参数和默认没有参数依次调用另外一个newing了所有的依赖关系,但是,在上述这本书被称为混蛋注射反模式,这是我以前所知道的穷人的注入。

In all the applications I've seen when an attempt to use DI is being made, there are always two constructors: the one with the dependencies as parameters and the "default" one with no parameters which in turn calls the other one "newing" up all the dependencies but, in the aforementioned book this is called the "Bastard Injection anti-pattern" and that is what I used to know as "Poor Man's Injection".

现在考虑这一切,我会说来,穷人的注入只想不使用IoC容器,而是通过手工编码的所有对象图上说的构成根会。

Now considering all this, I would say then that "Poor Man's Injection" would be just not using an IoC container and instead coding all the object graph by hand on the said Composition Root.

所以我的问题是:


  1. 我是不是完全正确的理解这些概念,还是我偏离了轨道?

  2. 如果您还需要注册在IoC容器里所有的依赖主场迎战完全相同的成分根采用手动编码方式,什么是使用IoC容器的真正好处?

  3. 如果我误会了穷人的注射液还真是,可能有人请澄清?

感谢

推荐答案

在谈到DI,有很多的冲突使用的术语在那里的。术语穷人的DI 也不例外。对某些人来说,这意味着一件事,对他人就意味着不同的东西。

When it comes to DI, there's a lot of conflicting use of terminology out there. The term Poor Man's DI is no exception. To some people, it means one thing and to others it means something different.

一个我想要的书做的事情是提供一个的相一致的模式为DI语言。当它来到所有冲突使用这些术语,我有两个选择:(根据我的主观判断)拿出一个全新的名词,或者选择最prevalent使用

One of the things I wanted to do with the book was to supply a consistent pattern language for DI. When it came to all of those terms with conflicting use, I had two options: Come up with a completely new term, or pick the most prevalent use (according to my subjective judgment).

在一般情况下,我已经pferred重新使用现有的术语,而不是做了一个全新的(因而外星人)模式语言$ P $。这意味着,在某些情况下(如穷人的DI),您可能必须的名称还有什么比在书中给出的定义不同的概念。这经常发生有图案的书籍。

In general, I've preferred to re-use existing terminology instead of making up a completely new (and thus alien) pattern language. That means that in certain cases (such as Poor Man's DI), you may have a different notion of what the name is than the definition given in the book. That often happens with patterns books.

至少我觉得很放心的,这本书似乎已经做解释究竟两者穷人的DI和庶子注射它的工作,因为在给定的O.P.间pretation是即期。

At least I find it reassuring that the book seems to have done its job of explaining exactly both Poor Man's DI and Bastard Injection, because the interpretation given in the O.P. is spot on.

对于一个DI容器的真正好处我会向您推荐这样的回答:<一href=\"http://stackoverflow.com/questions/5667801/arguments-against-inversion-of-control-containers/5668093#5668093\">Arguments对控制容器的反转

Regarding the real benefit of a DI Container I will refer you to this answer: Arguments against Inversion of Control containers

这篇关于有什么区别&QUOT真正的区别;庶子注塑和QUOT;和&QUOT;穷人的注塑和QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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