Open sandboxFocus

Method Add

Add<T>(Func<ServiceProvider<TService>, T>, bool)

Adds a lazily-created service to the builder.

Declaration
public void Add<T>(Func<ServiceProvider<TService>, T> func, bool allowOverride = false) where T : class, TService
Parameters
Type Name Description
Func<ServiceProvider<TService>, T> func

A factory function that creates the service instance when needed.

bool allowOverride

If true, allows overriding an existing service of the same type.

Type Parameters
Name Description
T

The interface type under which the service will be registered. This should be the service interface (e.g., IMetricProvider<SyntaxNodesCount>), not the concrete implementation type.

Add(TService, bool)

Adds a service instance to the builder.

Declaration
public void Add(TService service, bool allowOverride = false)
Parameters
Type Name Description
TService service

The service instance to add.

bool allowOverride

If true, allows overriding an existing service of the same type.

Add(Func<ServiceProvider<TService>, ServiceProvider<TService>>)

Adds a transformation function that modifies the service provider during the build process.

Declaration
public void Add(Func<ServiceProvider<TService>, ServiceProvider<TService>> func)
Parameters
Type Name Description
Func<ServiceProvider<TService>, ServiceProvider<TService>> func

A function that takes a service provider and returns a modified service provider.