Skip to content
This repository has been archived by the owner on Apr 5, 2021. It is now read-only.

Latest commit

 

History

History
139 lines (91 loc) · 2.73 KB

simpledependencyservice.md

File metadata and controls

139 lines (91 loc) · 2.73 KB

SimpleDependencyService class

Namespace: MADE.App.Dependency

Defines a simple dependency service. Based on SimpleIoc.

public class SimpleDependencyService : ISimpleDependencyService

Supported platforms

Platform Version
.NET Standard 2.0
Xamarin.Android 8.1
Xamarin.iOS 1.0
UWP 10.0.16299

Example

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

Static Properties

Instance

Gets an instance of the dependency service.

public static ISimpleDependencyService Instance { get; }

Methods

Register()

Registers the given type.

public void Register<TClass>() where TClass : class;

Register<TInterface, TClass>()

Registers the given interface and associated type.

public void Register<TInterface, TClass>()
            where TInterface : class 
            where TClass : class, TInterface;

Register(Func)

Registers the given type with the given factory.

public void Register<TClass>(Func<TClass> factory);

Parameters

factory (Func)

The factory for creating instances of the given type.

Register(string, Func)

Registers the given type with the given factory and associates it with the given key.

public void Register<TClass>(string key, Func<TClass> factory);

Parameters

key

The key associated with the registration.

factory (Func)

The factory for creating instances of the given type.

GetInstance()

Gets an instance of the given service type that is registered.

public TService GetInstance<TService>();

Returns

A registered instance of the given service.

GetInstance(string)

Gets an instance of the given service type that is registered.

public TService GetInstance<TService>(string key);

Parameters

key

The key of the instance to retrieve.

Returns

A registered instance of the given service.

IsRegistered()

Checks whether the given type is registered with the service.

public bool IsRegistered<T>();

Returns

True if the type is registered; otherwise, false.

IsRegistered(string)

public bool IsRegistered<T>(string key);

Parameters

key

The key of the instance to check is registered.

Returns

True if the type is registered; otherwise, false.