Ways of Dependency Injection

后端 未结 2 969
野性不改
野性不改 2021-01-15 08:58

Can the Factory Patterns (Factory Method,Simple Factory Method and Abstract Factory) or Service Locator Pattern way of fetching the dependency be called Dependency Injection

2条回答
  •  温柔的废话
    2021-01-15 09:25

    Dependency Injection and Service Locator are two opposing ways to program to interfaces, but Dependency Injection solves most problems and challenges far better than the Service Locator anti-pattern.

    Abstract Factories can be injected into services that need them, so can be combined with both approaches. They are perpendicular to the discussion, not a variation of Service Locator.

提交回复
热议问题