Common Service Registry

前端 未结 2 1247
孤城傲影
孤城傲影 2021-01-20 19:14

For a long time now we\'ve been fortunate enough to have the Common Service Locator (CSL) to resolve services from an unknown source. However, there has never been any conta

2条回答
  •  -上瘾入骨i
    2021-01-20 20:07

    The most decoupled (and the best) solution you can achieve is to realize that loose coupling is best achieved through principles and patterns instead of particular technologies.

    Use Constructor Injection throughout your application. The ensures that none of your application layers need reference any container at all. Then compose the entire application graph in the root of the application.

    You don't need to use a DI Container for this, but if you choose to use a DI Container, you must isolate it to the Composition Root. This means that if you later decide to migrate to a different container, you only need to change the Composition Root. However, Poor Man's DI is also an option.

提交回复
热议问题