依赖注入,只有基类的实例 [英] Example of Dependency Injection with only base class

查看:167
本文介绍了依赖注入,只有基类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能做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.

这篇关于依赖注入,只有基类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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