Question

As far as i know dependency injection is not the same as service location. but the Unity application block contains the Common Service Locator library (which i think is a service locator). how that library should be used and when should it be used, and is it being used by unity itself for dependency injection ?
NOTE: Please do not quote from CommonServiceLocator CodePlex homepage on its usage.

Was it helpful?

Solution

The Common Service Locator interface is intended for library authors who want to use a DI container without forcing the library's choice of container on the apps using the library. The intention is that inside the library where you need to resolve objects, you'd code against the CSL interface instead; then you can use whichever container the app calling you is using.

If you aren't writing a reusable library component, don't use the CSL. It's an additional layer that won't buy you anything.

OTHER TIPS

No, Dependency Injection is not the same thing as Service Location, however they do share a lot of functional similarities. What they do not share is more a philosophical approach.

Both provide access to objects as configured in your application. However, Dependency Injection says that you should never explicitly ask for an object (or interface). You should instead SPECIFY an object or interface, and the framework will deal with hooking everything up for you.

Service Location is where you request an object directly from the Service Locator system.

To put another way, Service Location requires that you find the object you want. Dependency Injection assumes you are created with the objects you need already in place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top