Class ServiceDescriptor
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- nanoFramework.DependencyInjection.dll
Describes a service with its service type, implementation, and lifetime.
public class ServiceDescriptor
- Inheritance
-
ServiceDescriptor
- Inherited Members
- Extension Methods
Constructors
ServiceDescriptor(Type, ImplementationFactoryDelegate, ServiceLifetime)
Initializes a new instance of ServiceDescriptor with the specified implementationFactory
.
public ServiceDescriptor(Type serviceType, ImplementationFactoryDelegate implementationFactory, ServiceLifetime lifetime)
Parameters
serviceType
TypeThe Type of the service.
implementationFactory
ImplementationFactoryDelegateA factory used for creating service instances.
lifetime
ServiceLifetimeThe ServiceLifetime of the service.
Exceptions
- ArgumentNullException
serviceType
can't be null- ArgumentNullException
implementationFactory
can't be null- ArgumentException
Implementation type cannot be an abstract or interface class.
ServiceDescriptor(Type, object)
Initializes a new instance of ServiceDescriptor with the specified instance
as a Singleton.
public ServiceDescriptor(Type serviceType, object instance)
Parameters
Exceptions
- ArgumentNullException
serviceType
orinstance
can't be null
ServiceDescriptor(Type, Type, ServiceLifetime)
Initializes a new instance of ServiceDescriptor with the specified implementationType
.
public ServiceDescriptor(Type serviceType, Type implementationType, ServiceLifetime lifetime)
Parameters
serviceType
TypeThe Type of the service.
implementationType
TypeThe Type implementing the service.
lifetime
ServiceLifetimeThe ServiceLifetime of the service.
Exceptions
- ArgumentNullException
serviceType
orimplementationType
can't be null- ArgumentException
Implementation type cannot be an abstract or interface class.
Properties
ImplementationFactory
Gets the factory used for creating service instances.
public ImplementationFactoryDelegate ImplementationFactory { get; set; }
Property Value
ImplementationInstance
The instance of the implementation.
public object ImplementationInstance { get; set; }
Property Value
ImplementationType
The Type implementing the service.
public Type ImplementationType { get; }
Property Value
Lifetime
The ServiceLifetime of the service.
public ServiceLifetime Lifetime { get; }
Property Value
ServiceType
The Type of the service.
public Type ServiceType { get; }
Property Value
Methods
Describe(Type, ImplementationFactoryDelegate, ServiceLifetime)
Creates an instance of ServiceDescriptor with the specified
serviceType
, implementationFactory
,
and lifetime
.
public static ServiceDescriptor Describe(Type serviceType, ImplementationFactoryDelegate implementationFactory, ServiceLifetime lifetime)
Parameters
serviceType
TypeThe type of the service.
implementationFactory
ImplementationFactoryDelegateA factory to create new instances of the service implementation.
lifetime
ServiceLifetimeThe lifetime of the service.
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
Describe(Type, Type, ServiceLifetime)
Creates an instance of ServiceDescriptor with the specified
serviceType
, implementationType
,
and lifetime
.
public static ServiceDescriptor Describe(Type serviceType, Type implementationType, ServiceLifetime lifetime)
Parameters
serviceType
TypeThe type of the service.
implementationType
TypeThe type of the implementation.
lifetime
ServiceLifetimeThe lifetime of the service.
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
GetImplementationType()
Returns the Type implementing the instance.
public Type GetImplementationType()
Returns
Scoped(Type, ImplementationFactoryDelegate)
Creates an instance of ServiceDescriptor with the specified
service
and implementationFactory
and the Scoped lifetime.
public static ServiceDescriptor Scoped(Type service, ImplementationFactoryDelegate implementationFactory)
Parameters
service
TypeThe type of the service.
implementationFactory
ImplementationFactoryDelegateA factory to create new instances of the service implementation.
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
Scoped(Type, Type)
Creates an instance of ServiceDescriptor with the specified
service
and implementationType
and the Scoped lifetime.
public static ServiceDescriptor Scoped(Type service, Type implementationType)
Parameters
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
Singleton(Type, ImplementationFactoryDelegate)
Creates an instance of ServiceDescriptor with the specified
service
and implementationFactory
and the Singleton lifetime.
public static ServiceDescriptor Singleton(Type service, ImplementationFactoryDelegate implementationFactory)
Parameters
service
TypeThe type of the service.
implementationFactory
ImplementationFactoryDelegateA factory to create new instances of the service implementation.
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
Singleton(Type, Type)
Creates an instance of ServiceDescriptor with the specified
service
and implementationType
and the Singleton lifetime.
public static ServiceDescriptor Singleton(Type service, Type implementationType)
Parameters
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
ToString()
Returns a string that represents the current object.
public override string ToString()
Returns
Transient(Type, ImplementationFactoryDelegate)
Creates an instance of ServiceDescriptor with the specified
service
and implementationFactory
and the Transient lifetime.
public static ServiceDescriptor Transient(Type service, ImplementationFactoryDelegate implementationFactory)
Parameters
service
TypeThe type of the service.
implementationFactory
ImplementationFactoryDelegateA factory to create new instances of the service implementation.
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.
Transient(Type, Type)
Creates an instance of ServiceDescriptor with the specified
service
and implementationType
and the Transient lifetime.
public static ServiceDescriptor Transient(Type service, Type implementationType)
Parameters
Returns
- ServiceDescriptor
A new instance of ServiceDescriptor.