How to avoid Service Locator Anti-Pattern?

前端 未结 3 1374
自闭症患者
自闭症患者 2020-12-17 17:01

I\'m trying to remove a Service Locator from an abstract base class, but I\'m not sure what to replace it with. Here is a psuedo-example of what I\'ve got:

p         


        
3条回答
  •  春和景丽
    2020-12-17 17:41

    Maybe you should just do away the Kernel, Types and MySpecialResolver and let the subclasses call DoActions with the IMyServiceInterface instances they need as argument directly. And let the subclasses decide how they get to these instances - they should know best (or in case they don't know which exactly the one who ever decides which instances of IMyServiceInterface are needed)

提交回复
热议问题