Table of Contents

Class Generator<TService>

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

Lazy generator to create multiple new services/objects of a specific type.

[InternalApi_DoNotUse_MayChangeWithoutNotice]
public class Generator<TService> : IHasLog where TService : class

Type Parameters

TService

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

Inheritance
object
Generator<TService>
Implements

Remarks

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

Constructors

Generator(IServiceProvider)

Lazy generator to create multiple new services/objects of a specific type.

public Generator(IServiceProvider sp)

Parameters

sp IServiceProvider

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()

Factory method to generate a new service

public TService New()

Returns

TService

New(string)

Factory method to generate a new service using a name/keyed.

public TService New(string key)

Parameters

key string

The key/name of the service to generate.

Returns

TService

Remarks

New in v22

SetInit(Action<TService>, bool)

Set the init-command as needed

public Generator<TService> SetInit(Action<TService> newInitCall, bool allowReplace = false)

Parameters

newInitCall Action<TService>
allowReplace bool

Allow replacing the set-init

Returns

Generator<TService>

TryNew(string)

public TService? TryNew(string key)

Parameters

key string

Returns

TService