Class ExtensibleFactory<TService, TSettingsBase>
- Namespace
- Silverback.ExtensibleFactories
- Assembly
- Silverback.Core.dll
The base class for factories used to allow extension in additional packages, for example adding other storage types.
public abstract class ExtensibleFactory<TService, TSettingsBase> where TService : notnull where TSettingsBase : IEquatable<TSettingsBase>
Type Parameters
TServiceThe type of the service to build.
TSettingsBaseThe base type of the settings to use.
- Inheritance
-
ExtensibleFactory<TService, TSettingsBase>
- Derived
- Inherited Members
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()
protected ExtensibleFactory()
Methods
AddFactory<TSettings>(Func<TSettings, IServiceProvider, TService>)
Registers the factory for the specified settings type.
public virtual void AddFactory<TSettings>(Func<TSettings, IServiceProvider, TService> factory) where TSettings : TSettingsBase
Parameters
factoryFunc<TSettings, IServiceProvider, TService>The factory building the
TServiceaccording to the specified settings.
Type Parameters
TSettingsThe type of the settings.
GetService<TSettings>(TSettings, IServiceProvider)
Returns an object of type TService according to the specified settings.
protected TService GetService<TSettings>(TSettings settings, IServiceProvider serviceProvider) where TSettings : TSettingsBase
Parameters
settingsTSettingsThe settings that will be used to create the service.
serviceProviderIServiceProviderThe IServiceProvider that can be used to resolve additional services.
Returns
- TService
The service of type
TService, ornullif no factory is registered for the specified settings type.
Type Parameters
TSettingsThe type of the settings.
HasFactory<TSettings>()
Returns a boolean value indicating whether a factory for the specified settings type is registered.
public bool HasFactory<TSettings>()
Returns
- bool
A value indicating whether a factory for the specified settings type is registered.
Type Parameters
TSettingsThe type of the settings.
OverrideFactories(Func<TSettingsBase, IServiceProvider, TService>)
Overrides all registered factories with the specified factory.
public void OverrideFactories(Func<TSettingsBase, IServiceProvider, TService> factory)
Parameters
factoryFunc<TSettingsBase, IServiceProvider, TService>The factory to be used regardless of the settings type.