Class ServiceProviderExtensions
Provides extension methods for System.IServiceProvider implemenations.
Inheritance
Namespace: EPiServer.ServiceLocation
Assembly: EPiServer.Framework.dll
Version: 12.0.3Syntax
public static class ServiceProviderExtensions : Object
Methods
CreateServiceLocatorScope(IServiceProvider)
Creates a Microsoft.Extensions.DependencyInjection.IServiceScope with support for Current
Declaration
public static IServiceScope CreateServiceLocatorScope(this IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The service provider. |
Returns
Type | Description |
---|---|
Microsoft.Extensions.DependencyInjection.IServiceScope | The scope |
GetAllInstances(IServiceProvider, Type)
Get all instances of the given serviceType
currently
registered in the container.
Declaration
public static IEnumerable<object> GetAllInstances(this IServiceProvider serviceProvider, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The serice provider. |
System.Type | serviceType | Type of object requested. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Object> | A sequence of instances of the requested |
GetAllInstances<TService>(IServiceProvider)
Get all instances of the given TService
currently
registered in the container.
Declaration
public static IEnumerable<TService> GetAllInstances<TService>(this IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The serice provider. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<TService> | A sequence of instances of the requested |
Type Parameters
Name | Description |
---|---|
TService | Type of object requested. |
Exceptions
Type | Condition |
---|---|
ActivationException | if there is are errors resolving the service instance. |
GetInstance(IServiceProvider, Type)
Get an instance of the given serviceType
.
Declaration
public static object GetInstance(this IServiceProvider serviceProvider, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The service provider. |
System.Type | serviceType | The requested service type. |
Returns
Type | Description |
---|---|
System.Object | The requested service instance. |
GetInstance<TService>(IServiceProvider)
Get an instance of the given TService
.
Declaration
public static TService GetInstance<TService>(this IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The serice provider. |
Returns
Type | Description |
---|---|
TService | The requested service instance. |
Type Parameters
Name | Description |
---|---|
TService |
TryGetExistingInstance(IServiceProvider, Type, out Object)
Tries to get an existing instance of the given serviceType
.
Declaration
public static bool TryGetExistingInstance(this IServiceProvider serviceProvider, Type serviceType, out object instance)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The serice provider. |
System.Type | serviceType | Type of object requested. |
System.Object | instance | The instance. |
Returns
Type | Description |
---|---|
System.Boolean | True if the instance was found |
TryGetExistingInstance<TService>(IServiceProvider, out TService)
Tries to get an existing instance of the given TService
.
Declaration
public static bool TryGetExistingInstance<TService>(this IServiceProvider serviceProvider, out TService instance)
Parameters
Type | Name | Description |
---|---|---|
System.IServiceProvider | serviceProvider | The serice provider. |
TService | instance | The requested service instance or null if it do not exist |
Returns
Type | Description |
---|---|
System.Boolean | True if the instance was found |
Type Parameters
Name | Description |
---|---|
TService | Type of object requested. |
Exceptions
Type | Condition |
---|---|
ActivationException | if there is are errors resolving the service instance. |