This project is read-only.


EasyLocator is an easy IoC Container that implements IServiceLocator (Microsoft.Practices.ServiceLocation).
It allows you to register Services and instances.
  • Named registering : You can name Services and instances if you want to store several instances of a type or retrieve them easily.
  • Caching Strategy : by default you get new instances every time you try to get one. You can also keep alive instances and cache them.
  • EasyLocator uses Reflection to Resolve not registered types . Also registering ViewModels for example is not required. EasyLocator registers them and instanciates them for you . Only registering Services is really required (pair interface + implementation for example) because it can't resolves the "preferred" implementation .

You can download from CodePlex or use Packages NuGet .

Registering a Service

  • With Static member
 EasyLocator.Default.Register<IService, Service>();
  • Or creates a new instance of EasyLocator (EasyLocator implements ILocator, IServiceLocator and IServiceProvider)
var container = new EasyLocator();
container.Register<IService, Service>();
  • Registering a named Service
EasyLocator.Default.Register<IService, Service>("serviceOne");
EasyLocator.Default.Register<IService, OtherService>("serviceTwo");
  • Caching Strategy : Keep alive an instance
  • Multiples registrations
var container = new EasyLocator();
container.Register<IService, Service>()
                .RegisterInstance<Product>(new Product("p1"));
  • With a base class
 EasyLocator.Default.Register<Person, Employee>();

Retrieving a service

 var instance = EasyLocator.Default.GetInstance<IService>();

 var instance = EasyLocator.Default.GetInstance<Person>();
  • Retrieving a named Service
 var instance = EasyLocator.Default.GetInstance<IService>("serviceTwo");

Registering an instance

 var p1= new Product();
  • Registering several instances of a same type and name them
 var p1= new Product();
 var p2= new Product();

EasyLocator.Default.RegisterInstance<Product>(p2, "productTwo");
  • Other samples : with Static Method
  • with Enum

Retrieving an instance

var  instance = EasyLocator.Default.GetInstance<Product>();
  • Retrieving an instance by name
var  instance = EasyLocator.Default.GetInstance<Product>("productTwo");


  • Setting up the Service Locator provider
 ServiceLocator.SetLocatorProvider(() => EasyLocator.Default);
  • Registering a service with EasyLocator
 EasyLocator.Default.Register<IService, Service>();
  • And finally retrieving it with Microsoft.Practices.ServiceLocation.ServiceLocator
var service = ServiceLocator.Current.GetInstance<IService>();


Last edited Sep 17, 2014 at 10:22 AM by romagny13, version 29