依赖注入,只有基类的实例实例

由网友(笑.)分享简介:是否有可能做DI没有任何第三方工具?我读过有关的人与一个抽象类和接口做,他们发现了一些DI​​框架之前。在非常基本的形式是如何做的ID?Is it possible to do DI without any third party tools? I've read about people doing it wit...

是否有可能做DI没有任何第三方工具?我读过有关的人与一个抽象类和接口做,他们发现了一些DI​​框架之前。在非常基本的形式是如何做的ID?

Is it possible to do DI without any third party tools? I've read about people doing it with an abstract class and interface before they discovered some DI framework. How is ID done in that very basic form?

推荐答案

只是传递依赖的类的构造函数,当你实例化它。不需要DI框架时,该项目是很小(低于几千行code) - 你可以写一个工厂来包装所有的依赖手动

Just pass the dependencies to the constructor of the class when you instantiate it. No DI frameworks are needed when the project is small (below a couple of thousand lines of code) - you can write a factory and wire up all the dependencies manually.

阅读全文

相关推荐

最新文章