November Happy Hour will be moved to Thursday December 5th.

Class ServiceDescriptor

Describes a registration of a concrete implementation for an service/abstraction.

Inheritance
System.Object
ServiceDescriptor
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 class ServiceDescriptor

Constructors

ServiceDescriptor(Type, Func<IServiceLocator, Object>, ServiceInstanceScope)

Initializes a new instance of ServiceDescriptor with the specified factory.

Declaration
public ServiceDescriptor(Type serviceType, Func<IServiceLocator, object> factory, ServiceInstanceScope lifetime)
Parameters
Type Name Description
System.Type serviceType

The System.Type of the service.

System.Func<IServiceLocator, System.Object> factory

A factory used for creating service instances.

ServiceInstanceScope lifetime

The ServiceInstanceScope of the service.

ServiceDescriptor(Type, Object)

Initializes a new instance of ServiceDescriptor with the specified instance as a Singleton.

Declaration
public ServiceDescriptor(Type serviceType, object instance)
Parameters
Type Name Description
System.Type serviceType

The System.Type of the service.

System.Object instance

The instance implementing the service.

ServiceDescriptor(Type, Type, ServiceInstanceScope)

Initializes a new instance of ServiceDescriptor with the specified implementationType.

Declaration
public ServiceDescriptor(Type serviceType, Type implementationType, ServiceInstanceScope lifetime)
Parameters
Type Name Description
System.Type serviceType
System.Type implementationType
ServiceInstanceScope lifetime

Properties

ImplementationFactory

Declaration
public Func<IServiceLocator, object> ImplementationFactory { get; }
Property Value
Type Description
System.Func<IServiceLocator, System.Object>

ImplementationInstance

The implementation instance

Declaration
public object ImplementationInstance { get; }
Property Value
Type Description
System.Object

ImplementationType

The implementation type

Declaration
public Type ImplementationType { get; }
Property Value
Type Description
System.Type

IncludeServiceAccessor

Specifies if a ServiceAccessor<TService> should be added for the service.

Declaration
public bool IncludeServiceAccessor { get; set; }
Property Value
Type Description
System.Boolean

Lifetime

The lifecycle that the created instances should have

Declaration
public ServiceInstanceScope Lifetime { get; }
Property Value
Type Description
ServiceInstanceScope

ServiceType

The service type

Declaration
public Type ServiceType { get; }
Property Value
Type Description
System.Type

Methods

AddServiceAccessor()

Adds a ServiceAccessor<TService> instance for the service.

Declaration
public ServiceDescriptor AddServiceAccessor()
Returns
Type Description
ServiceDescriptor

The service descriptor instance

Instance(Type, Object)

Creates a singleton lifecycled service descriptor for a service instance.

Declaration
public static ServiceDescriptor Instance(Type serviceType, object implementationInstance)
Parameters
Type Name Description
System.Type serviceType

The service type

System.Object implementationInstance

The singleton instance

Returns
Type Description
ServiceDescriptor

A service descriptor

Instance<TService>(TService)

Creates a singleton lifecycled service descriptor for a service instance.

Declaration
public static ServiceDescriptor Instance<TService>(TService implementationInstance)
    where TService : class
Parameters
Type Name Description
TService implementationInstance

The singleton instance

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

Scoped(Type, Func<IServiceLocator, Object>)

Creates a hybrid (httpcontext or thread local) lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Scoped(Type service, Func<IServiceLocator, object> implementationFactory)
Parameters
Type Name Description
System.Type service

The service type

System.Func<IServiceLocator, System.Object> implementationFactory

The factory to use

Returns
Type Description
ServiceDescriptor

A service descriptor

Scoped(Type, Type)

Creates a hybrid (httpcontext or thread local) lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Scoped(Type service, Type implementationType)
Parameters
Type Name Description
System.Type service

The service type

System.Type implementationType

The implementation type

Returns
Type Description
ServiceDescriptor

A service descriptor

Scoped<TService>(Func<IServiceLocator, TService>)

Creates a hybrid (httpcontext or thread local) lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Scoped<TService>(Func<IServiceLocator, TService> implementationFactory)
    where TService : class
Parameters
Type Name Description
System.Func<IServiceLocator, TService> implementationFactory

The factory to use

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

Scoped<TService, TImplementation>()

Creates a hybrid (httpcontext or thread local) lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Scoped<TService, TImplementation>()
    where TService : class where TImplementation : class, TService
Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

TImplementation

The implementation type

Scoped<TService, TImplementation>(Func<IServiceLocator, TImplementation>)

Creates a hybrid (httpcontext or thread local) lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Scoped<TService, TImplementation>(Func<IServiceLocator, TImplementation> implementationFactory)
    where TService : class where TImplementation : class, TService
Parameters
Type Name Description
System.Func<IServiceLocator, TImplementation> implementationFactory

The factory to use

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

TImplementation

The implementation type

Singleton(Type, Func<IServiceLocator, Object>)

Creates a singleton lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Singleton(Type serviceType, Func<IServiceLocator, object> implementationFactory)
Parameters
Type Name Description
System.Type serviceType

The service type

System.Func<IServiceLocator, System.Object> implementationFactory

The factory

Returns
Type Description
ServiceDescriptor

A service descriptor

Singleton(Type, Type)

Creates a singleton lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Singleton(Type service, Type implementationType)
Parameters
Type Name Description
System.Type service

The service type

System.Type implementationType

The factory to use

Returns
Type Description
ServiceDescriptor

A service descriptor

Singleton<TService>(Func<IServiceLocator, TService>)

Creates a singleton lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Singleton<TService>(Func<IServiceLocator, TService> implementationFactory)
    where TService : class
Parameters
Type Name Description
System.Func<IServiceLocator, TService> implementationFactory

The factory

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

Singleton<TService, TImplementation>()

Creates a singleton lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Singleton<TService, TImplementation>()
    where TService : class where TImplementation : class, TService
Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

TImplementation

The factory to use

Singleton<TService, TImplementation>(Func<IServiceLocator, TImplementation>)

Creates a singleton lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Singleton<TService, TImplementation>(Func<IServiceLocator, TImplementation> implementationFactory)
    where TService : class where TImplementation : class, TService
Parameters
Type Name Description
System.Func<IServiceLocator, TImplementation> implementationFactory

The factory

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

TImplementation

The factory to use

Transient(Type, Func<IServiceLocator, Object>)

Creates a transient lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Transient(Type service, Func<IServiceLocator, object> implementationFactory)
Parameters
Type Name Description
System.Type service

The service type

System.Func<IServiceLocator, System.Object> implementationFactory

The factory

Returns
Type Description
ServiceDescriptor

A service descriptor

Transient(Type, Type)

Creates a transient lifecycled service descriptor.

Declaration
public static ServiceDescriptor Transient(Type service, Type implementationType)
Parameters
Type Name Description
System.Type service

The service type

System.Type implementationType

The implementation type

Returns
Type Description
ServiceDescriptor

A service descriptor

Transient<TService>(Func<IServiceLocator, TService>)

Creates a transient lifecycled service descriptor for a service type.

Declaration
public static ServiceDescriptor Transient<TService>(Func<IServiceLocator, TService> implementationFactory)
    where TService : class
Parameters
Type Name Description
System.Func<IServiceLocator, TService> implementationFactory

The factory

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

Transient<TService, TImplementation>()

Creates a transient lifecycled service descriptor.

Declaration
public static ServiceDescriptor Transient<TService, TImplementation>()
    where TService : class where TImplementation : class, TService
Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

TImplementation

The implementation type

Transient<TService, TImplementation>(Func<IServiceLocator, TImplementation>)

Creates a transient lifecycled service descriptor.

Declaration
public static ServiceDescriptor Transient<TService, TImplementation>(Func<IServiceLocator, TImplementation> implementationFactory)
    where TService : class where TImplementation : class, TService
Parameters
Type Name Description
System.Func<IServiceLocator, TImplementation> implementationFactory

The factory to use

Returns
Type Description
ServiceDescriptor

A service descriptor

Type Parameters
Name Description
TService

The service type

TImplementation

The implementation type

Extension Methods