For DI to work, you must have an interface whose concrete class you can inject into the consumer of the behavior you desire.
为了让DI工作,必须拥有一个接口,可以把这个接口的具体类注入到需要的行为的消费者中。
Many proponents of DI prefer constructor injection, because it means that the injected class never exists in a state where its dependencies aren't present.
许多 DI 的支持者愿意采用构造函数注入,因为这意味着注入的类永远不会出现依赖项不存在的情况。
With DI, you can allow the container to inject the appropriate customer class either by configuring the container or implementing the injection in the code.
使用DI,可以通过配置容器或在代码中实现注入,让容器注入适合的客户类。
应用推荐