Class TypeBasedExtensibleFactory<TService, TDiscriminatorBase>
The base class for factories used to allow extension in additional packages, for example adding broker-specific extensions.
Inheritance
Inherited Members
Namespace: Silverback.ExtensibleFactories
Assembly: Silverback.Core.dll
Syntax
public abstract class TypeBasedExtensibleFactory<TService, TDiscriminatorBase> where TService : notnull where TDiscriminatorBase : IEquatable<TDiscriminatorBase>
Type Parameters
| Name | Description |
|---|---|
| TService | The type of the service to build. |
| TDiscriminatorBase | The discriminator base type. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
Constructors
TypeBasedExtensibleFactory(bool)
Initializes a new instance of the TypeBasedExtensibleFactory<TService, TDiscriminatorBase> class.
Declaration
protected TypeBasedExtensibleFactory(bool cacheInstances = true)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | cacheInstances | A value indicating whether the instances should be cached. If |
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<TDiscriminator>(Func<IServiceProvider, TService>)
Registers the factory for the specified discriminator implementation type.
Declaration
public virtual void AddFactory<TDiscriminator>(Func<IServiceProvider, TService> factory) where TDiscriminator : TDiscriminatorBase
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IServiceProvider, TService> | factory | The factory building the |
Type Parameters
| Name | Description |
|---|---|
| TDiscriminator | The discriminator implementation type. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
GetService(Type, IServiceProvider)
Returns an object of type TService according to the specified discriminator.
Declaration
protected TService? GetService(Type discriminatorType, IServiceProvider serviceProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| Type | discriminatorType | The discriminator implementation type. |
| IServiceProvider | serviceProvider | The IServiceProvider that can be used to resolve additional services. |
Returns
| Type | Description |
|---|---|
| TService | The service of type |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
GetService(TDiscriminatorBase, IServiceProvider)
Returns an object of type TService according to the specified discriminator.
Declaration
protected TService? GetService(TDiscriminatorBase discriminator, IServiceProvider serviceProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| TDiscriminatorBase | discriminator | The discriminator. |
| IServiceProvider | serviceProvider | The IServiceProvider that can be used to resolve additional services. |
Returns
| Type | Description |
|---|---|
| TService | The service of type |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator
HasFactory<TDiscriminator>()
Returns a boolean value indicating whether a factory for the specified discriminator type is registered.
Declaration
public bool HasFactory<TDiscriminator>() where TDiscriminator : TDiscriminatorBase
Returns
| Type | Description |
|---|---|
| bool | A value indicating whether a factory for the specified discriminator type is registered. |
Type Parameters
| Name | Description |
|---|---|
| TDiscriminator | The discriminator implementation type. |
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<IServiceProvider, TService>)
Overrides all registered factories with the specified factory.
Declaration
public void OverrideFactories(Func<IServiceProvider, TService> factory)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<IServiceProvider, TService> | factory | The factory to be used regardless of the discriminator type. |
Remarks
Two versions are available:
- TypeBasedExtensibleFactory<TService, TDiscriminatorBase>, using just a type as discriminator
- ExtensibleFactory<TService, TSettingsBase>, using a settings record as discriminator