# ServiceProvider

Namespace: **Wisej.Services**

Assembly: **Wisej.Framework** (4.0.0.0)

Manages services for Wisej.NET's DI implementation.

{% tabs %}
{% tab title="C#" %}

```csharp
public class ServiceProvider : IServiceProvider
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class ServiceProvider
    Inherits IServiceProvider
```

{% endtab %}
{% endtabs %}

## Methods

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService\<TService>(lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The service to add.                                                                                                         |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService(serviceType, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService\<TService, TImplementation>(lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The type of the service to add.                                                                                             |
| **TImplementation**                                                                                                                                                                                                        |                                                                                                     | The type of the implementation to use.                                                                                      |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService(serviceType, implementationType, lifetime)

Registers a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **implementationType**                                                                                                                                                                                                     | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the implementation to use.                                                                                      |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null or empty.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *implementationType* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService\<TService>(implementationTypeName, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The type of the service to add.                                                                                             |
| **implementationTypeName**                                                                                                                                                                                                 | [String](https://docs.microsoft.com/dotnet/api/system.string)                                       | The name of the type of the implementation; can be a fully qualified assembly + type name.                                  |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

Using this overload allows the application to register a service implementation that is loaded dynamically when requested. If *implementationTypeName* is a fully qualified type name, including the assembly name, the assembly and type are loaded on demand. **Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *implementationTypeName* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService(serviceType, implementationTypeName, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **implementationTypeName**                                                                                                                                                                                                 | [String](https://docs.microsoft.com/dotnet/api/system.string)                                       | The name of the type of the implementation; can be a fully qualified assembly + type name.                                  |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

Using this overload allows the application to register a service implementation that is loaded dynamically when requested. If *implementationTypeName* is a fully qualified type name, including the assembly name, the assembly and type are loaded on demand. This non-generic method supports the registration of generic services:

```csharp

![
  Application.Services.AddService(typeof(DBConnection<>));
  ...
  var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
  var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null or empty.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *implementationTypeName* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService\<TService>(serviceImplementation, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The service to add.                                                                                                         |
| **serviceImplementation**                                                                                                                                                                                                  | [Object](https://docs.microsoft.com/dotnet/api/system.object)                                       | Implementation for the *TService* .                                                                                         |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceImplementation* is null.
* [InvalidCastException](https://docs.microsoft.com/dotnet/api/system.invalidcastexception) *serviceImplementation* cannot be assigned to *TService* .
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService(serviceType, serviceImplementation, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The service to add.                                                                                                         |
| **serviceImplementation**                                                                                                                                                                                                  | [Object](https://docs.microsoft.com/dotnet/api/system.object)                                       | Implementation for the *serviceType* .                                                                                      |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceImplementation* is null.
* [InvalidCastException](https://docs.microsoft.com/dotnet/api/system.invalidcastexception) *serviceImplementation* cannot be assigned to *serviceType* .
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService\<TService>(implementationFactory, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The type of the service to add.                                                                                             |
| **implementationFactory**                                                                                                                                                                                                  | [Func\<Type, Object>](https://docs.microsoft.com/dotnet/api/system.func-2)                          | Method for creating the *TService* instance.                                                                                |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [NullReferenceException](https://docs.microsoft.com/dotnet/api/system.nullreferenceexception) *implementationFactory* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddOrReplaceService(serviceType, implementationFactory, lifetime)

Registers or replaces a scoped service. <mark style="color:blue;background-color:green;">Since 4.0.0</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **implementationFactory**                                                                                                                                                                                                  | [Func\<Type, Object>](https://docs.microsoft.com/dotnet/api/system.func-2)                          | Method for creating the *serviceType* instance.                                                                             |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [NullReferenceException](https://docs.microsoft.com/dotnet/api/system.nullreferenceexception) *serviceType* is null.
* [NullReferenceException](https://docs.microsoft.com/dotnet/api/system.nullreferenceexception) *implementationFactory* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService\<TService>(lifetime)

Registers a scoped service.

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The service to add.                                                                                                         |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService(serviceType, lifetime)

Registers a scoped service. <mark style="color:blue;background-color:green;">Since 3.5.4</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService\<TService, TImplementation>(lifetime)

Registers a scoped service.

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The type of the service to add.                                                                                             |
| **TImplementation**                                                                                                                                                                                                        |                                                                                                     | The type of the implementation to use.                                                                                      |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService(serviceType, implementationType, lifetime)

Registers a scoped service. <mark style="color:blue;background-color:green;">Since 3.5.4</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **implementationType**                                                                                                                                                                                                     | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the implementation to use.                                                                                      |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null or empty.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *implementationType* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService\<TService>(implementationTypeName, lifetime)

Registers a scoped service.

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The type of the service to add.                                                                                             |
| **implementationTypeName**                                                                                                                                                                                                 | [String](https://docs.microsoft.com/dotnet/api/system.string)                                       | The name of the type of the implementation; can be a fully qualified assembly + type name.                                  |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

Using this overload allows the application to register a service implementation that is loaded dynamically when requested. If *implementationTypeName* is a fully qualified type name, including the assembly name, the assembly and type are loaded on demand. **Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *implementationTypeName* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService(serviceType, implementationTypeName, lifetime)

Registers a scoped service. <mark style="color:blue;background-color:green;">Since 3.5.4</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **implementationTypeName**                                                                                                                                                                                                 | [String](https://docs.microsoft.com/dotnet/api/system.string)                                       | The name of the type of the implementation; can be a fully qualified assembly + type name.                                  |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

Using this overload allows the application to register a service implementation that is loaded dynamically when requested. If *implementationTypeName* is a fully qualified type name, including the assembly name, the assembly and type are loaded on demand. This non-generic method supports the registration of generic services:

```csharp

![
  Application.Services.AddService(typeof(DBConnection<>));
  ...
  var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
  var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null or empty.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *implementationTypeName* is null or empty.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService\<TService>(serviceImplementation, lifetime)

Registers a scoped service.

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The service to add.                                                                                                         |
| **serviceImplementation**                                                                                                                                                                                                  | [Object](https://docs.microsoft.com/dotnet/api/system.object)                                       | Implementation for the *TService* .                                                                                         |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceImplementation* is null.
* [InvalidCastException](https://docs.microsoft.com/dotnet/api/system.invalidcastexception) *serviceImplementation* cannot be assigned to *TService* .
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService(serviceType, serviceImplementation, lifetime)

Registers a scoped service. <mark style="color:blue;background-color:green;">Since 3.5.4</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The service to add.                                                                                                         |
| **serviceImplementation**                                                                                                                                                                                                  | [Object](https://docs.microsoft.com/dotnet/api/system.object)                                       | Implementation for the *serviceType* .                                                                                      |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null.
* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceImplementation* is null.
* [InvalidCastException](https://docs.microsoft.com/dotnet/api/system.invalidcastexception) *serviceImplementation* cannot be assigned to *serviceType* .
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService\<TService>(implementationFactory, lifetime)

Registers a scoped service.

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **TService**                                                                                                                                                                                                               |                                                                                                     | The type of the service to add.                                                                                             |
| **implementationFactory**                                                                                                                                                                                                  | [Func\<Type, Object>](https://docs.microsoft.com/dotnet/api/system.func-2)                          | Method for creating the *TService* instance.                                                                                |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [NullReferenceException](https://docs.microsoft.com/dotnet/api/system.nullreferenceexception) *implementationFactory* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *TService* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) AddService(serviceType, implementationFactory, lifetime)

Registers a scoped service. <mark style="color:blue;background-color:green;">Since 3.5.4</mark>

| Parameter                                                                                                                                                                                                                  | Type                                                                                                | Description                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **serviceType**                                                                                                                                                                                                            | [Type](https://docs.microsoft.com/dotnet/api/system.type)                                           | The type of the service to add.                                                                                             |
| **implementationFactory**                                                                                                                                                                                                  | [Func\<Type, Object>](https://docs.microsoft.com/dotnet/api/system.func-2)                          | Method for creating the *serviceType* instance.                                                                             |
| **lifetime** ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-723b640963c6cd781ff8c5ce5b24149fa0af7b9c%2Fbadge-optional.svg?alt=media) | [ServiceLifetime](https://docs.wisej.com/api/wisej.services/general/wisej.services.servicelifetime) | Scope of the service. Default is [Shared](https://docs.wisej.com/api/wisej.services/wisej.services.servicelifetime#fields). |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

This non-generic method supports the registration of generic services:

```csharp

![
    Application.Services.AddService(typeof(DBConnection<>));
    ...
    var dbTrucks = Application.Services.GetService<DBConnection<Truck>>);
    var dbEmployees = Application.Services.GetService<DBConnection<Employee>>);

```

**Throws:**

* [NullReferenceException](https://docs.microsoft.com/dotnet/api/system.nullreferenceexception) *serviceType* is null.
* [NullReferenceException](https://docs.microsoft.com/dotnet/api/system.nullreferenceexception) *implementationFactory* is null.
* [InvalidOperationException](https://docs.microsoft.com/dotnet/api/system.invalidoperationexception) A service of type *serviceType* is already registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) GetService\<T>()

Returns the requested service.

| Parameter | Type | Description                      |
| --------- | ---- | -------------------------------- |
| **T**     |      | Type of the service to retrieve. |

**Returns:** [T](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider). An instance of *T* or null if the service is not found.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) GetService(serviceType)

Returns the requested service.

| Parameter       | Type                                                      | Description                 |
| --------------- | --------------------------------------------------------- | --------------------------- |
| **serviceType** | [Type](https://docs.microsoft.com/dotnet/api/system.type) | Type of the service to add. |

**Returns:** [Object](https://docs.microsoft.com/dotnet/api/system.object). An instance of *serviceType* or null if the service is not found.

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) HasService\<T>()

Checks if a service of type *T* is already registered. <mark style="color:blue;background-color:green;">Since 3.5.12</mark>

| Parameter | Type | Description            |
| --------- | ---- | ---------------------- |
| **T**     |      | Service type to check. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the service is registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) HasService(serviceType)

Checks if a service of type *serviceType* is already registered. <mark style="color:blue;background-color:green;">Since 3.5.12</mark>

| Parameter       | Type                                                      | Description            |
| --------------- | --------------------------------------------------------- | ---------------------- |
| **serviceType** | [Type](https://docs.microsoft.com/dotnet/api/system.type) | Service type to check. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the service is registered.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) Inject(target)

Injects the services into the properties marked with the [InjectAttribute](https://docs.wisej.com/api/wisej.services/general/wisej.services.injectattribute) attributed on the specified *target* object.

| Parameter  | Type                                                          | Description                                |
| ---------- | ------------------------------------------------------------- | ------------------------------------------ |
| **target** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | Target object to inject dependencies into. |

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *target* is null.

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) RemoveService\<TService>()

Removes the specified service type from the service container.

| Parameter    | Type | Description            |
| ------------ | ---- | ---------------------- |
| **TService** |      | The service to remove. |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

### ![](https://1075938901-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2HvlWXJQMV7DxhGzw7Y1%2Fuploads%2Fgit-blob-2389c55cd19719a73a5ae98e1528c8dc8525cc35%2Finstance.png?alt=media) RemoveService(serviceType)

Removes the specified service type from the service container.

| Parameter       | Type                                                      | Description                    |
| --------------- | --------------------------------------------------------- | ------------------------------ |
| **serviceType** | [Type](https://docs.microsoft.com/dotnet/api/system.type) | Type of the service to remove. |

**Returns:** [ServiceProvider](https://docs.wisej.com/api/wisej.services/general/wisej.services.serviceprovider).

**Throws:**

* [ArgumentNullException](https://docs.microsoft.com/dotnet/api/system.argumentnullexception) *serviceType* is null.
