tryAddKeyedSingleton<TService> method

void tryAddKeyedSingleton<TService>(
  1. Object? serviceKey,
  2. KeyedImplementationFactory implementationFactory
)

Adds the specified TService as a ServiceLifetime.singleton service with the specified serviceKey using the factory specified in implementationFactory to the services if the service type hasn't already been registered with that key.

Implementation

void tryAddKeyedSingleton<TService>(
  Object? serviceKey,
  KeyedImplementationFactory implementationFactory,
) {
  var descriptor = ServiceDescriptor.keyedSingleton<TService>(
    serviceKey,
    (services) => implementationFactory,
  );
  tryAdd(descriptor);
}