Namespace: MADE.App.Dependency
Defines a simple dependency service. Based on SimpleIoc.
public class SimpleDependencyService : ISimpleDependencyService
Platform | Version |
---|---|
.NET Standard | 2.0 |
Xamarin.Android | 8.1 |
Xamarin.iOS | 1.0 |
UWP | 10.0.16299 |
Use the SimpleDependencyService.Current property to get an instance of the service for the current app.
using MADE.App.Dependency;
ISimpleDependencyService service = SimpleDependencyService.Current;
service.Register<IMyService, MyService>(); // Registers the service
IMyService myService = service.GetInstance<IMyService>(); // Retrieves the registered instance
Gets an instance of the dependency service.
public static ISimpleDependencyService Instance { get; }
Registers the given type.
public void Register<TClass>() where TClass : class;
Registers the given interface and associated type.
public void Register<TInterface, TClass>()
where TInterface : class
where TClass : class, TInterface;
Registers the given type with the given factory.
public void Register<TClass>(Func<TClass> factory);
The factory for creating instances of the given type.
Registers the given type with the given factory and associates it with the given key.
public void Register<TClass>(string key, Func<TClass> factory);
The key associated with the registration.
The factory for creating instances of the given type.
Gets an instance of the given service type that is registered.
public TService GetInstance<TService>();
A registered instance of the given service.
Gets an instance of the given service type that is registered.
public TService GetInstance<TService>(string key);
The key of the instance to retrieve.
A registered instance of the given service.
Checks whether the given type is registered with the service.
public bool IsRegistered<T>();
True if the type is registered; otherwise, false.
public bool IsRegistered<T>(string key);
The key of the instance to check is registered.
True if the type is registered; otherwise, false.