-
-
Notifications
You must be signed in to change notification settings - Fork 0
How to Use
Ken Tucker edited this page Dec 6, 2024
·
1 revision
var serviceType = typeof(IService);
var result = CommonServiceLocator.ServiceLocator.Current.GetService(serviceType);
This returns a ServiceImpl
var result = CommonServiceLocator.ServiceLocator.Current.GetInstance<IService>();
This returns a ServiceImpl
var serviceType = typeof(IPet);
var key = "Cat";
var result = CommonServiceLocator.ServiceLocator.Current.GetInstance(serviceType, key);
This returns an instance of Cat
var key = "Dog";
var result = CommonServiceLocator.ServiceLocator.Current.GetInstance<IPet>(key);
This returns an instance of Dog
var serviceType = typeof(IService);
var result = CommonServiceLocator.ServiceLocator.Current.GetInstance(serviceType);
This returns a ServiceImpl
var result = CommonServiceLocator.ServiceLocator.Current.GetInstance<IService>();
This returns a ServiceImpl
var result = CommonServiceLocator.ServiceLocator.Current.GetAllInstances(typeof(IPet));
Will return an IEnumerable that contains a Cat and Dog
var result = CommonServiceLocator.ServiceLocator.Current.GetAllInstances<ICar>()
Will return an IEnumerable that contains a Ford, Chevy and Toyota
Passing a null in as the key will return the first of the Type registered
var serviceType = typeof(IPet);
var result = CommonServiceLocator.ServiceLocator.Current.GetInstance(serviceType, null);
Will return the First IPet registered for DependencyInjection in this case an instance of the Dog class
All examples are based on what is registered in the How to register your services section