Show / Hide Table of Contents

Class ServiceProviderOrActivatorResolver

An implementation of IResolvesServices which attempts to use an System.IServiceProvider, but will fall back upon System.Activator.CreateInstance(System.Type) if the service provider was unable to resolve the service.

Inheritance
System.Object
ServiceProviderOrActivatorResolver
Implements
IResolvesServices
IResolvesRule
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: CSF.Validation.Bootstrap
Assembly: CSF.Validation.dll
Syntax
public class ServiceProviderOrActivatorResolver : IResolvesServices, IResolvesRule

Constructors

| Improve this Doc View Source

ServiceProviderOrActivatorResolver(IServiceProvider)

Initialises an instance of ServiceProviderOrActivatorResolver.

Declaration
public ServiceProviderOrActivatorResolver(IServiceProvider serviceProvider)
Parameters
Type Name Description
System.IServiceProvider serviceProvider

The service provider.

Exceptions
Type Condition
System.ArgumentNullException

If serviceProvider is null.

Methods

| Improve this Doc View Source

ResolveService<T>(Type)

Attempts to resolve an instance of the specified implementation type.

Declaration
public T ResolveService<T>(Type implementationType)
Parameters
Type Name Description
System.Type implementationType

The type of the concrete implementation for the service.

Returns
Type Description
T

An instance of the requested service; this method will not return null, it will raise an exception instead.

Type Parameters
Name Description
T

The expected type of the service.

Remarks

Attempts to resolve an instance of the specified implementationType, or raises an exception if this is not possible. This might occur for user/developer-provided services, particularly if they are not correctly registered via dependency injection. This method will make attempts to resolve the service regardless, and might succeed where a plain System.IServiceProvider would fail.

Exceptions
Type Condition
ResolutionException

If a service instance could not be resolved successfully.

System.ArgumentNullException

If implementationType is null.

System.ArgumentException

If the implementationType does not derive from T.

Explicit Interface Implementations

| Improve this Doc View Source

IResolvesRule.ResolveRule(Type)

Declaration
object IResolvesRule.ResolveRule(Type ruleType)
Parameters
Type Name Description
System.Type ruleType
Returns
Type Description
System.Object

Implements

IResolvesServices
IResolvesRule
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX