From what I understand IServiceLocator is an interface to abstract the actual IoC container away? I'm asking with relation to Prism where I'm trying to replace Unity with Prism, and I see Prism-classes relying on IServiceLocator. Could someone please clarify the role of the interface and when it is used?
And also; what is the Common Service Locator, and will this be helpful when working with IServiceLocator?
IServiceLocator is an abstraction of a service locator. IoC containers are kind of supersets of service locators so they can be represented by IServiceLocator. However, the service locator pattern is more intrusive than the pure dependency injection pattern, therefore you should try to favor the latter whenever possible.
The CommonServiceLocator provides the IServiceLocator interface and an abstract implementation of this interface to define common behavior and help IoC containers define their IServiceLocator adapter (every major IoC container provides such an adapter).
See also:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With