Class ServiceLocatorImplBase
This class is a helper that provides a default implementation for most of the methods of IServiceLocator.
Inherited Members
Namespace: EPiServer.ServiceLocation
Assembly: EPiServer.Framework.dll
Version: 10.10.4Syntax
public abstract class ServiceLocatorImplBase : IServiceLocator, IServiceProvider
Remarks
This derives from http://commonservicelocator.codeplex.com/.
Constructors
ServiceLocatorImplBase()
Declaration
protected ServiceLocatorImplBase()
Methods
Buildup(Object)
Satisfies the dependencies of the given service using setter injection.
Declaration
public abstract void Buildup(object service)
Parameters
Type | Name | Description |
---|---|---|
System.Object | service | The object whose property depdenencies should be set. |
DoGetAllInstances(Type)
When implemented by inheriting classes, this method will do the actual work of resolving all the requested service instances.
Declaration
protected abstract IEnumerable<object> DoGetAllInstances(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of service requested. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Object> | Sequence of service instance objects. |
DoGetInstance(Type, String)
When implemented by inheriting classes, this method will do the actual work of resolving the requested service instance.
Declaration
protected abstract object DoGetInstance(Type serviceType, string key)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of instance requested. |
System.String | key | Name of registered service you want. May be null. |
Returns
Type | Description |
---|---|
System.Object | The requested service instance. |
DoTryGetExistingInstance(Type, String, out Object)
When implemented by inheriting classes, this method will look if the instance has been created and that it exists.
Declaration
protected abstract bool DoTryGetExistingInstance(Type serviceType, string key, out object instance)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of instance requested. |
System.String | key | Name of registered service you want. May be null. |
System.Object | instance | The requested service instance. Null if not existing |
Returns
Type | Description |
---|---|
System.Boolean | True if the instance was found |
FormatActivateAllExceptionMessage(Exception, Type)
Format the exception message for use in an ActivationException that occurs while resolving multiple service instances.
Declaration
protected virtual string FormatActivateAllExceptionMessage(Exception actualException, Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | actualException | The actual exception thrown by the implementation. |
System.Type | serviceType | Type of service requested. |
Returns
Type | Description |
---|---|
System.String | The formatted exception message string. |
FormatActivationExceptionMessage(Exception, Type, String)
Format the exception message for use in an ActivationException that occurs while resolving a single service.
Declaration
protected virtual string FormatActivationExceptionMessage(Exception actualException, Type serviceType, string key)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | actualException | The actual exception thrown by the implementation. |
System.Type | serviceType | Type of service requested. |
System.String | key | Name requested. |
Returns
Type | Description |
---|---|
System.String | The formatted exception message string. |
GetAllInstances(Type)
Get all instances of the given serviceType
currently
registered in the container.
Declaration
public virtual 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 |
Exceptions
Type | Condition |
---|---|
ActivationException | if there is are errors resolving the service instance. |
GetAllInstances<TService>()
Get all instances of the given TService
currently
registered in the container.
Declaration
public virtual IEnumerable<TService> GetAllInstances<TService>()
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(Type)
Get an instance of the given serviceType
.
Declaration
public virtual 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(Type, String)
Get an instance of the given named serviceType
.
Declaration
public virtual object GetInstance(Type serviceType, string key)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of object requested. |
System.String | key | Name the object was registered with. |
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
public virtual 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. |
GetInstance<TService>(String)
Get an instance of the given named TService
.
Declaration
public virtual TService GetInstance<TService>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Name the object was registered with. |
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. |
GetService(Type)
Implementation of System.IServiceProvider.GetService(System.Type).
Declaration
public virtual object GetService(Type serviceType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | The requested service. |
Returns
Type | Description |
---|---|
System.Object | The requested object. |
Exceptions
Type | Condition |
---|---|
ActivationException | if there is an error in resolving the service instance. |
TryGetExistingInstance(Type, out Object)
Tries to get an existing instance of the given serviceType
.
Declaration
public virtual 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. |
TryGetExistingInstance(Type, String, out Object)
Tries to get an existing instance of the given named serviceType
.
Declaration
public virtual bool TryGetExistingInstance(Type serviceType, string key, out object instance)
Parameters
Type | Name | Description |
---|---|---|
System.Type | serviceType | Type of object requested. |
System.String | key | Name the object was registered with. |
System.Object | instance | The requested service instance or null if it do not exist |
Returns
Type | Description |
---|---|
System.Boolean | True if the instance was found |
Exceptions
Type | Condition |
---|---|
ActivationException | if there is an error resolving the service instance. |
TryGetExistingInstance<TService>(out TService)
Tries to get an existing instance of the given TService
.
Declaration
public virtual bool TryGetExistingInstance<TService>(out TService instance)
Parameters
Type | Name | Description |
---|---|---|
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. |
TryGetExistingInstance<TService>(String, out TService)
Tries to get an existing instance of the given named TService
.
Declaration
public virtual bool TryGetExistingInstance<TService>(string key, out TService instance)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Name the object was registered with. |
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. |