开发者

Why do we need common service locator library?

I have a 3 layered application. Front, Business, Data layer. I have used Microsoft Unity as the dependency container. I have used NUnit with RhinoMock to test the application.

I have read in many articles to introduce a common service locator layer.

** In which scnerios should we introduce common service locator?

  1. Which layer would it replace in the project with the architecture explained abov开发者_开发百科e?
  2. Which layer will it communicate to in my project?

  3. Is common service locator layer just a WCF web service project that communicates to business and front layer?**


Why do we need common service locator library?

We do not really need it, it just provides a better separation. It is mostly an abstraction on the top of Dependency injection so that the client would not need to know where the service is located and how it is implemented.

This would normally go to your client code. For example, a client which creates a proxy and calls a service, would not need to create the proxy, it asks for it from a service locator.


I think you're referring to a common way of locating dependencies (i.e. services), so in your example it would replace Unity (or perhaps Unity would just implement the common interface).

This way all sorts of frameworks would work together a bit more easily as they share a common way of identifying services / plugins etc.

We already have lots of libraries that achieve the functionality (Unity, Ninject etc), but if a framework (e.g. MVC) wants to get an instance of some interface it needs to know which library you are using, and since they don't share a common interface this is difficult. With a common interface you can tell MVC where you want it to get it's objects from.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜