Class LazySvc<TService>
Helps us create lazy Service objects. It has some special features:
- It will automatically lazy-attach a logger when used correctly
- It can also be configured with a lazy init function to keep code clean.
This reduces the amount of plumbing in many code files.
It will detect if the provided object/service supports these features.
So if it's used for anything that doesn't support logging it will just behave like Lazy
.
Implements
Namespace: ToSic.Lib.DI
Assembly: ToSic.Lib.Core.dll
Syntax
[InternalApi_DoNotUse_MayChangeWithoutNotice]
public class LazySvc<TService> : IHasLog where TService : class
Type Parameters
Name | Description |
---|---|
TService | Service type, ideally based on ServiceBase |
Constructors
| Improve this Doc View SourceLazySvc(IServiceProvider)
Constructor, should never be called as it's only meant to be used with Dependency Injection.
Declaration
public LazySvc(IServiceProvider sp)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | sp |
Properties
| Improve this Doc View SourceIsValueCreated
Declaration
public bool IsValueCreated { get; }
Property Value
Type | Description |
---|---|
bool |
Log
The parent log, which is attached to newly generated objects if they support logging.
Declaration
public ILog Log { get; }
Property Value
Type | Description |
---|---|
ILog |
Value
Declaration
public TService Value { get; }
Property Value
Type | Description |
---|---|
TService |
Methods
| Improve this Doc View SourceInject(TService)
EXPERIMENTAL - replace a service with an already prepared one, to bypass the default factory in edge cases
Declaration
public void Inject(TService replacement)
Parameters
Type | Name | Description |
---|---|---|
TService | replacement |
SetInit(Action<TService>)
Set the init-command as needed
Declaration
public LazySvc<TService> SetInit(Action<TService> newInitCall)
Parameters
Type | Name | Description |
---|---|---|
Action<TService> | newInitCall |
Returns
Type | Description |
---|---|
LazySvc<TService> |