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);
Namespace: Eremex.AvaloniaUI.Controls.ApplicationServices
Assembly: Eremex.Avalonia.Controls.ApplicationServices.dll
NuGet Package: Eremex.Avalonia.Controls.ApplicationServices
Declaration
public void AddSingleton(Type serviceType, Func<IServiceProvider, object> factory)
Parameters
| name |
type |
description |
| serviceType |
Type |
The type the service is resolved by, normally an interface. |
| factory |
Func<IServiceProvider, object> |
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.
Namespace: Eremex.AvaloniaUI.Controls.ApplicationServices
Assembly: Eremex.Avalonia.Controls.ApplicationServices.dll
NuGet Package: Eremex.Avalonia.Controls.ApplicationServices
Declaration
public void AddSingleton<TService>(TService instance)
where TService : class
Type Parameters
| name |
description |
| TService |
The type the service is resolved by, normally an interface. |
Parameters
| name |
type |
description |
| instance |
TService |
The instance returned for every request of TService. |
Exceptions
| exception |
condition |
| ArgumentNullException |
instance is null. |
See Also