Skip to content

SimpleServiceProvider.AddSingleton method (1 of 2)

Registers a service factory. The instance is created on first request. The signature is compatible with RegisterApplicationServices: ApplicationServicesContext.RegisterApplicationServices(provider.AddSingleton);

public void AddSingleton(Type serviceType, Func<IServiceProvider, object> factory)
parameter description
serviceType The type the service is resolved by, normally an interface.
factory Creates the instance on first request. It receives this provider, so a service may resolve its own dependencies through it.

Exceptions

exception condition
ArgumentNullException serviceType or factory is null.

See Also


SimpleServiceProvider.AddSingleton<TService> method (2 of 2)

Registers a ready instance under the TService type. The type is stated explicitly so a service cannot be accidentally registered under its concrete class instead of its interface.

public void AddSingleton<TService>(TService instance)
    where TService : class
parameter description
TService The type the service is resolved by, normally an interface.
instance The instance returned for every request of TService.

Exceptions

exception condition
ArgumentNullException instance is null.

See Also