Class ExtensibleFactory<TService, TSettingsBase>
The base class for factories used to allow extension in additional packages, for example adding other storage types.
Inheritance
Inherited Members
Namespace: Silverback.ExtensibleFactories
Assembly: Silverback.Core.dll
Syntax
public abstract class ExtensibleFactory<TService, TSettingsBase> where TService : notnull where TSettingsBase : IEquatable<TSettingsBase>
Type Parameters
| Name | Description |
|---|---|
| TService | The type of the service to build. |
| TSettingsBase | The base type of the settings to use. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
Constructors
ExtensibleFactory()
The base class for factories used to allow extension in additional packages, for example adding other storage types.
Declaration
protected ExtensibleFactory()
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
Methods
AddFactory<TSettings>(Func<TSettings, IServiceProvider, TService>)
Registers the factory for the specified settings type.
Declaration
public virtual void AddFactory<TSettings>(Func<TSettings, IServiceProvider, TService> factory) where TSettings : TSettingsBase
Parameters
| Type | Name | Description |
|---|---|---|
| Func<TSettings, IServiceProvider, TService> | factory | The factory building the |
Type Parameters
| Name | Description |
|---|---|
| TSettings | The type of the settings. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
GetService<TSettings>(TSettings, IServiceProvider)
Returns an object of type TService according to the specified settings.
Declaration
protected TService GetService<TSettings>(TSettings settings, IServiceProvider serviceProvider) where TSettings : TSettingsBase
Parameters
| Type | Name | Description |
|---|---|---|
| TSettings | settings | The settings that will be used to create the service. |
| IServiceProvider | serviceProvider | The IServiceProvider that can be used to resolve additional services. |
Returns
| Type | Description |
|---|---|
| TService | The service of type |
Type Parameters
| Name | Description |
|---|---|
| TSettings | The type of the settings. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
HasFactory<TSettings>()
Returns a boolean value indicating whether a factory for the specified settings type is registered.
Declaration
public bool HasFactory<TSettings>()
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether a factory for the specified settings type is registered. |
Type Parameters
| Name | Description |
|---|---|
| TSettings | The type of the settings. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
OverrideFactories(Func<TSettingsBase, IServiceProvider, TService>)
Overrides all registered factories with the specified factory.
Declaration
public void OverrideFactories(Func<TSettingsBase, IServiceProvider, TService> factory)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<TSettingsBase, IServiceProvider, TService> | factory | The factory to be used regardless of the settings type. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator