# 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.md): `ApplicationServicesContext.RegisterApplicationServices(provider.AddSingleton);`

```csharp
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

* class [SimpleServiceProvider](../SimpleServiceProvider.md)
* namespace [Eremex.AvaloniaUI.Controls.ApplicationServices](../index.md)

---

# SimpleServiceProvider.AddSingleton&lt;TService&gt; 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.

```csharp
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

* class [SimpleServiceProvider](../SimpleServiceProvider.md)
* namespace [Eremex.AvaloniaUI.Controls.ApplicationServices](../index.md)

<!-- DO NOT EDIT: generated by xmldocmd for Eremex.Avalonia.Controls.ApplicationServices.dll -->
