What is the real difference between “Bastard Injection” and “Poor Man's Injection”

后端 未结 3 1913
时光说笑
时光说笑 2020-11-28 06:23

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 o

3条回答
  •  渐次进展
    2020-11-28 06:48

    We've found, when refactoring legacy applications and decoupling dependencies, that things tend to be easier when done with a two step process. The process includes both "poor man" and formal IoC container systems.

    First: set up interfaces and establish "poor mans ioc" to implement them.

    • This decouples dependencies without the added overhead (and learning curve) of a formal IoC set up.
    • This also reduces interference with the existing legacy code. Nothing like introducing yet another set of issues to debug.
    • Development team members are never at the same level of expertise or understanding. So it saves a lot of implementation time.
    • This also allows a footing for test cases.
    • This also establishes standards for a formal IoC container system later.
    • This can be implemented in steps over time by many people.

    Secondly: Each IoC system has pros & cons.

    • Now that an application standard is established, an educated decision can be made in choosing an IoC container system.
    • Implementing the IoC system becomes a task of swapping the "poor mans" code with the new IoC system.
    • This can be implemented in steps over time and in parallel with "poor man". It is better to head this with one person.

提交回复
热议问题