This repository was archived by the owner on Aug 27, 2020. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 37
 
IDependencyService
        Mark Smith edited this page Sep 2, 2016 
        ·
        4 revisions
      
    The IDependencyService interface is a simple representation of a Service Locator. The library provides a default implementation (DependencyServiceWrapper which wraps the Xamarin.Forms static DependencyService. However you can create your own and register it through the XamUInfrastructure.Init method.
- 
Get<T>: returns aTobject. - 
Register<T> : registers aT` object. - 
Register<T,TImpl> : registers aTImplobject as aT` abstraction. 
Here is a sample implementation that wraps the Microsoft Unity container:
public class UnityWrapper : IDependencyService
{
    UnityContainer container;
    public UnityWrapper(UnityContainer container)
    {
       this.container = container;
    }
    public T Get<T>() where T : class
    {
        return container.Resolve<T>();
    }
    public void Register<T> () where T : class, new()
    {
        container.RegisterType<T>();
    }
    public void Register<T, TImpl> () 
        where T : class
        where TImpl : class, T, new()
    {
        container.RegisterType<T,TImpl>();
    }
}