Class Generator<TService, TOptions>
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
TServiceThe service to generate. It must implement IServiceWithSetup<TOptions>
TOptionsThe options to configure the service
- Inheritance
-
objectGenerator<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
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
Methods
New(string, TOptions)
Retrieve a keyed service by key, with options.
public TService New(string key, TOptions options)
Parameters
keystringKey used in the registration - will throw if not found
optionsTOptionsOptions 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
optionsTOptionsOptions 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
keystringKey used in the registration - will return null
optionsTOptionsOptions 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.