Try our conversational search powered by Generative AI!

Class ServiceLocator

This class provides the ambient container for this application. If your framework defines such an ambient container, use ServiceLocator.Current to get it.

Inheritance
System.Object
ServiceLocator
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.ServiceLocation
Assembly: EPiServer.Framework.dll
Version: 11.20.7
Syntax
public static class ServiceLocator
Remarks

Properties

Current

The current ambient container.

Declaration
public static IServiceLocator Current { get; }
Property Value
Type Description
IServiceLocator

Methods

AssignNullService<TService>(IServiceLocator, ref TService)

Assigns a service reference using the service locator if not already assigned. This method is used internally by EPiServer to simplify optional service parameters.

Declaration
public static bool AssignNullService<TService>(this IServiceLocator locator, ref TService potentiallyEmptyServiceReference)
Parameters
Type Name Description
IServiceLocator locator

The service locator instance to use.

TService potentiallyEmptyServiceReference

The object referenced that is checked for null before beeing assigned.

Returns
Type Description
System.Boolean

True if a service was assigned, otherwise null.

Type Parameters
Name Description
TService

The type of service to retrieve.

SetLocator(IServiceLocator)

Sets the service locator provider to a service locator provider using the given service locator.

Declaration
public static void SetLocator(IServiceLocator serviceLocator)
Parameters
Type Name Description
IServiceLocator serviceLocator

The container to use for the global service locator instance.

SetLocatorProvider(ServiceLocatorProvider)

Set the delegate that is used to retrieve the current container.

Declaration
public static void SetLocatorProvider(ServiceLocatorProvider newProvider)
Parameters
Type Name Description
ServiceLocatorProvider newProvider

Delegate that, when called, will return the current ambient container.