Try our conversational search powered by Generative AI!

Interface IServiceLocator

The generic Service Locator interface. This interface is used to retrieve services (instances identified by type and optional name) from a container.

Inherited Members
System.IServiceProvider.GetService(System.Type)
Namespace: EPiServer.ServiceLocation
Assembly: EPiServer.Framework.dll
Version: 11.20.7
Syntax
public interface IServiceLocator : IServiceProvider
Remarks

Methods

GetAllInstances(Type)

Get all instances of the given serviceType currently registered in the container.

Declaration
IEnumerable<object> GetAllInstances(Type serviceType)
Parameters
Type Name Description
System.Type serviceType

Type of object requested.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.Object>

A sequence of instances of the requested serviceType.

Exceptions
Type Condition
ActivationException

if there is are errors resolving the service instance.

GetInstance(Type)

Get an instance of the given serviceType.

Declaration
object GetInstance(Type serviceType)
Parameters
Type Name Description
System.Type serviceType

Type of object requested.

Returns
Type Description
System.Object

The requested service instance.

Exceptions
Type Condition
ActivationException

if there is an error resolving the service instance.

GetInstance<TService>()

Get an instance of the given TService.

Declaration
TService GetInstance<TService>()
Returns
Type Description
TService

The requested service instance.

Type Parameters
Name Description
TService

Type of object requested.

Exceptions
Type Condition
ActivationException

if there is are errors resolving the service instance.

TryGetExistingInstance(Type, out Object)

Tries to get an existing instance of the given serviceType.

Declaration
bool TryGetExistingInstance(Type serviceType, out object instance)
Parameters
Type Name Description
System.Type serviceType

Type of object requested.

System.Object instance
Returns
Type Description
System.Boolean

True if the instance was found

Exceptions
Type Condition
ActivationException

if there is an error resolving

The requested service instance or null if it do not exist the service instance.

Extension Methods