Show / Hide Table of Contents

    Class ExtensibleFactory<TService, TSettingsBase>

    The base class for factories used to allow extension in additional packages, for example adding other storage types.

    Inheritance
    object
    ExtensibleFactory<TService, TSettingsBase>
    DistributedLockFactory
    KafkaOffsetStoreFactory
    OutboxReaderFactory
    OutboxWriterFactory
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    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 TService according to the specified settings.

    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 TService, or null if no factory is registered for the specified settings 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
    GitHub E-Mail
    ↑ Back to top © 2026 Sergio Aquilini