Table of Contents

Class Generator<TService, TOptions>

Namespace
ToSic.Sys.DI
Assembly
ToSic.Sys.Core.dll

Generator to create multiple new services/objects of a specific type requiring options for setup.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public class Generator<TService, TOptions> : IHasLog where TService : class, IServiceWithSetup<TOptions> where TOptions : class?

Type Parameters

TService

The service to generate. It must implement IServiceWithSetup<TOptions>

TOptions

The options to configure the service

Inheritance
object
Generator<TService, TOptions>
Implements
Derived

Remarks

Constructor should only be used in DI context and never be called directly.

Constructors

Generator(ISysServiceProvider)

Generator to create multiple new services/objects of a specific type requiring options for setup.

public Generator(ISysServiceProvider sp)

Parameters

sp ISysServiceProvider

Remarks

Constructor should only be used in DI context and never be called directly.

Properties

Log

The parent log, which is attached to newly generated objects if they support logging.

public ILog? Log { get; }

Property Value

ILog

Methods

New(string, TOptions)

Retrieve a keyed service by key, with options.

public TService New(string key, TOptions options)

Parameters

key string

Key used in the registration - will throw if not found

options TOptions

Options for setting up the service, usually non-null, or it will throw an error once it's accessed

Returns

TService

The service, ready and initialized.

Exceptions

NotSupportedException

Throws if the provided options have the wrong type.

New(TOptions)

Factory method to generate a new service

public TService New(TOptions options)

Parameters

options TOptions

Options for setting up the service, usually non-null, or it will throw an error once it's accessed

Returns

TService

The service, ready and initialized.

TryNew(string, TOptions)

Try to retrieve a keyed service by key, with options.

public TService? TryNew(string key, TOptions options)

Parameters

key string

Key used in the registration - will return null

options TOptions

Options for setting up the service, usually non-null, or it will throw an error once it's accessed

Returns

TService

The service, ready and initialized - or null.

Exceptions

NotSupportedException

Throws if the provided options have the wrong type.