Back to Class Reference home page
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 |
---|
public void Register(IService service)
Registers an instance of a certain service.
service
- Service to be registered.
public void Register<T>() where T : IService
Registers a reference to a certain service type, without instantly instantiating it.
T
- Type of service to be registered (must be a subclass of IService).
public void RegisterAll(Assembly assembly = null)
Traverses all services that are located in a given assembly and registers their types, without instantly instantiating them.
assembly
- The assembly to be scanned. If NULL or not specified, the calling assembly will be scanned.
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.
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.
public bool Contains<T>()
Returns TRUE if a certain kind of service has been registered, FALSE otherwise.
T
- Type of service to be retrieved (must be a subclass of IService).
TRUE if a certain kind of service has been registered, FALSE otherwise.
public bool Contains(Type type)
Returns TRUE if a certain kind of service has been registered, FALSE otherwise.
type
- Type of service to be retrieved (must be a subclass of IService).
TRUE if a certain kind of service has been registered, FALSE otherwise.
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.
T
- Type of service to be retrieved (must be a subclass of IService), or of the class to instantiate.
Instance of the requested service or class.
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.
type
- Type of service to be retrieved (must be a subclass of IService), or of the class to instantiate.
Instance of the requested service or class.