Interface IServiceRegistrationProvider
Provides facilities to register a service.
A service must implement an interface that resides outside of its implementing assembly. A service that implements an interface in its own assembly will not be accessible by any consumer due to resolution rules. This is true even for a service that only exposes a private API. In such case, it is advisable to expose an internal API, and use System.Runtime.CompilerServices.InternalsVisibleToAttribute to expose the interface.
Namespace: Snowflake.Services
Assembly: Snowflake.Framework.Primitives.dll
Syntax
public interface IServiceRegistrationProvider
Methods
RegisterService<T>(T)
Registers a singleton service with the service container, in order to be accessible to other incoming IComposables. IComposable modules are loaded in dependency order; until all dependencies as specified using ImportServiceAttribute attributes are satisfiable by the loader, the composable will not be loaded. Hence it is important that services be registered this way.
A service must implement an interface that resides outside of its implementing assembly. A service that implements an interface in its own assembly will not be accessible by any consumer due to resolution rules; this is true even for a service that only exposes a private API. In such case, it is advisable to manually manage the lifetime of your service, or expose an internal API, and use System.Runtime.CompilerServices.InternalsVisibleToAttribute to expose the interface to another assembly. There is no restriction on module however; registering an instance of an interface that resides in a different assembly, but in the same module as the registering asembly, is perfectly fine.
Declaration
void RegisterService<T>(T serviceInstance)
where T : class
Parameters
| Type | Name | Description |
|---|---|---|
| T | serviceInstance | The instance of the service to register. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the service to register. |
Exceptions
| Type | Condition |
|---|---|
| System.ArgumentException | Thrown when a service of the same type was already registered. |
| System.InvalidOperationException | Thrown when a service and its implementing type reside in the same assembly. |