开发者

Regarding Service Locator Pattern

Service Locator seems like a pretty useful concept and I'd like to implement it in my app. However, I have a few questions about how it should be implemented and how it should be used in conjunction with other programming paradigms.

  1. Should the SL manage the service it is storing? That is, when the SL gets destroyed, should it also destroy the service itself, or 开发者_JAVA百科should it leave that to whoever registered the service?

  2. What about Dependency Injection? Now that I have an SL is there any point in passing the SL around as a parameter or should I access it globally? After all, much of the whole purpose of DI is covered by SL as well, and I wouldn't like to clutter a lot of my functions with one more parameter.


You would think I wrote this article (I didn't), considering how often I refer to it:

Service Locator is an Anti-Pattern

Dependency Injection makes your dependencies explicit. Service Location buries them in the implementation, and creates a hard dependency on your locator.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜