Introducing an IoC Container to Legacy Code

后端 未结 2 1682
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 05:10

I\'m writing a new .NET library for internal use at my company that will use IoC through Dependency Injection. Naturally, this library will be much easier to use if we use

2条回答
  •  不知归路
    2020-12-10 05:54

    You can use a facade / proxy pattern to hide the DI Container from your legacy container. You are essentially hardwiring your legacy to a custom class that you implement which will know about the DI container. Now if you modify your DI you update your facades not your legacy code.

    I've not done a lot of research into Common Service Locator but it's premise might be a good solution. You might want to tie your facade to the CSL, this will hide the DI concept completly from your legacy code.

提交回复
热议问题