To integrate a container into this interface, you need to implement the IServiceLocator interface:

namespace Microsoft.Practices.ServiceLocation
    public interface IServiceLocator : IServiceProvider
        object GetInstance(Type serviceType);
        object GetInstance(Type serviceType, string key);
        IEnumerable<object> GetAllInstances(Type serviceType);

        TService GetInstance<TService>();
        TService GetInstance<TService>(string key);
        IEnumerable<TService> GetAllInstances<TService>();

There are generic and non-generic versions of each of the three methods. To save you some time, the library also contains the ServiceLocatorImplBase class, which provides standard implementations of the various overloads, so all you need to implement is the object GetInstance(Type, string) and IEnumerable<object> GetAllInstances(Type) methods.

See the API Reference for details of the various methods and required behavior.

Last edited Sep 30, 2008 at 9:07 AM by ctavares, version 5


No comments yet.