79

Does any one know where Microsoft.Practices.ServiceLocation comes from? This is a namespace and a dll used in MS EnterpriseLibrary. Admittedly it's a very simple dll with just a handful of classes (using reflector), but I can't find published source code for it. It's not in Enterprise Library project and not in Unity project.

So does someone know if the source code for this was published and where? And also why is it not part of Unity? Is it used anywhere else?

Liam
  • 27,717
  • 28
  • 128
  • 190
Andrew Savinykh
  • 25,351
  • 17
  • 103
  • 158

3 Answers3

68

It comes from: https://github.com/unitycontainer/commonservicelocator

From the project description:

The Common Service Locator library contains a shared interface for service location which application and framework developers can reference. The library provides an abstraction over IoC containers and service locators. Using the library allows an application to indirectly access the capabilities without relying on hard references. The hope is that using this library, third-party applications and frameworks can begin to leverage IoC/Service Location without tying themselves down to a specific implementation.

This abstraction is implemented by several IoC frameworks out there, and Unity is one of them. nevertheless, Unity is not the owner of that project.

This way StructureMap, for example, provides implementation of those clases, so other frameworks (such as Prism from patterns & practices) can easily work with other IoC frameworks and not be bound to Unity itself.

makerofthings7
  • 60,103
  • 53
  • 215
  • 448
Julian Dominguez
  • 2,573
  • 21
  • 15
  • 1
    Notice that not only Prism but the Enterprise Library itself is now container-agnostic and can run with other IoC containers. – Grigori Melnik Nov 23 '10 at 00:30
  • 2
    I had the same error but I had Enterprise library 4.1 installed on my machine and my fellow developer who added the Enterprise library reference to our common solution had Enterprise Library version 5 checked in. So you may have an Enterprise library version issue. –  Jan 17 '11 at 23:36
  • 2
    CommonServiceLocator version 2.0 no longer includes the Microsoft.Practices.ServiceLocation. Maybe its just moved? I downgraded (Nuget) to CommonServiceLocator 1.3 and the project reference Microsoft.Practices.ServiceLocation is back. – srock Nov 01 '17 at 16:51
  • 10
    There is a breaking change since CommonServiceLocator 2.0.1. The namespace `Microsoft.Practices.ServiceLocation` is changed to `CommonServiceLocator`. @srock so no need to downgrade. – MonkeyDreamzzz May 18 '18 at 11:39
15

If you want you can grab the NuGet package here:

http://www.nuget.org/packages/CommonServiceLocator/

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
  • 1
    I'm having the issue that the original poster mentioned. Leniel, I tried your solution of installing the NuGet package CommonServiceLocator, but it didn't solve my problem. I'm guessing that things have changed since you mentioned this solution back on 2013. Do you know how they have changed? – Rod Jun 21 '18 at 20:11
  • 1
    @Rod: not really... I hit this error long time ago. Never had the need of working with this library again. – Leniel Maccaferri Sep 18 '19 at 18:50
4

Its a part of Enterprise Library : http://msdn.microsoft.com/en-us/library/ff664629(PandP.50).aspx.

Download it, together with documentation, from http://entlib.codeplex.com/.