Open sandboxFocus

Method AddShared

AddShared<T>(Func<ServiceProvider<TService>, T>)

Adds a lazily-created shared service to the builder. Shared services are instantiated once and shared across all service provider instances in the same family.

Declaration
public void AddShared<T>(Func<ServiceProvider<TService>, T> func) where T : class, TService
Parameters
Type Name Description
Func<ServiceProvider<TService>, T> func

A factory function that creates the service instance when needed.

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.

AddShared(TService)

Adds a shared service instance to the builder. Shared services are shared across all service provider instances in the same family.

Declaration
public void AddShared(TService service)
Parameters
Type Name Description
TService service

The service instance to add.