MVVMbasics Logo

mobilemotion.eu Logo


Back to Class Reference home page


MVVMbasics.Helpers
Class ServiceRegistry

MVVMbasics.Helpers.ServiceRegistry
 

 
public class ServiceRegistry

Simple IoC container that allows services to be registered and retrieved. All services must implement the IService interface.


Method Summary
void  Register(IService service)
Registers an instance of a certain service.
void  Register<T>() where T : IService
Registers a reference to a certain service type, without instantly instantiating it.
void  RegisterAll(Assembly assembly = null)
Traverses all services that are located in a given assembly and registers their types, without instantly instantiating them.
void  RegisterAll(string ns, Assembly assembly = null)
Traverses all services that are located in a given namespace inside a given assembly and registers their types, without instantly instantiating them.
bool  Contains<T>()
Returns TRUE if a certain kind of service has been registered, FALSE otherwise.
bool  Contains(Type type)
Returns TRUE if a certain kind of service has been registered, FALSE otherwise.
object  Resolve<T>()
Returns a matching service type if a service type is passed as parameter and a matching service has been registered. Otherwise, instantiates the given type be resolving all its constructor parameters, and returns the created instance.
object  Resolve(Type type)
Returns a matching service type if a service type is passed as parameter and a matching service has been registered. Otherwise, instantiates the given type be resolving all its constructor parameters, and returns the created instance.
 
Method Detail

Register

public void Register(IService service)

Registers an instance of a certain service.

Parameters:

service - Service to be registered.


Register<T>

public void Register<T>() where T : IService

Registers a reference to a certain service type, without instantly instantiating it.

Type Parameters:

T - Type of service to be registered (must be a subclass of IService).


RegisterAll

public void RegisterAll(Assembly assembly = null)

Traverses all services that are located in a given assembly and registers their types, without instantly instantiating them.

Parameters:

assembly - The assembly to be scanned. If NULL or not specified, the calling assembly will be scanned.


RegisterAll

public void RegisterAll(string ns, Assembly assembly = null)

Traverses all services that are located in a given namespace inside a given assembly and registers their types, without instantly instantiating them.

Parameters:

ns - Namespace to be scanned. If ends with '.*', also sub-directories will be scanned. If NULL, the whole assembly will be scanned.
assembly - The assembly to be scanned. If NULL, the calling assembly will be scanned.


Contains<T>

public bool Contains<T>()

Returns TRUE if a certain kind of service has been registered, FALSE otherwise.

Type Parameters:

T - Type of service to be retrieved (must be a subclass of IService).

Returns:

TRUE if a certain kind of service has been registered, FALSE otherwise.


Contains

public bool Contains(Type type)

Returns TRUE if a certain kind of service has been registered, FALSE otherwise.

Parameters:

type - Type of service to be retrieved (must be a subclass of IService).

Returns:

TRUE if a certain kind of service has been registered, FALSE otherwise.


Resolve<T>

public object Resolve<T>()

Returns a matching service type if a service type is passed as parameter and a matching service has been registered. Otherwise, instantiates the given type be resolving all its constructor parameters, and returns the created instance.

Type Parameters:

T - Type of service to be retrieved (must be a subclass of IService), or of the class to instantiate.

Returns:

Instance of the requested service or class.


Resolve

public object Resolve(Type type)

Returns a matching service type if a service type is passed as parameter and a matching service has been registered. Otherwise, instantiates the given type be resolving all its constructor parameters, and returns the created instance.

Parameters:

type - Type of service to be retrieved (must be a subclass of IService), or of the class to instantiate.

Returns:

Instance of the requested service or class.