Table of Contents

Class LazySvc<TService>

Namespace
ToSic.Lib.DI
Assembly
ToSic.Lib.Core.dll

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.

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

Type Parameters

TService

Service type, ideally based on ServiceBase

Inheritance
LazySvc<TService>
Implements

Remarks

Constructor, should never be called as it's only meant to be used with Dependency Injection.

Constructors

LazySvc(IServiceProvider)

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.

public LazySvc(IServiceProvider sp)

Parameters

sp IServiceProvider

Service provider, in case we need to debug something

Remarks

Constructor, should never be called as it's only meant to be used with Dependency Injection.

Properties

IsValueCreated

public bool IsValueCreated { get; }

Property Value

bool

Log

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

public ILog Log { get; }

Property Value

ILog

Value

public TService Value { get; }

Property Value

TService

Methods

Inject(TService)

EXPERIMENTAL - replace a service with an already prepared one, to bypass the default factory in edge cases

public void Inject(TService replacement)

Parameters

replacement TService

SetInit(Action<TService>)

Set the init-command as needed

public LazySvc<TService> SetInit(Action<TService> newInitCall)

Parameters

newInitCall Action<TService>

Returns

LazySvc<TService>