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
Inherited Members
Namespace: CSF.Validation.Bootstrap
Assembly: CSF.Validation.dll
Syntax
public class ServiceProviderOrActivatorResolver : IResolvesServices, IResolvesRule
Constructors
| Improve this Doc View SourceServiceProviderOrActivatorResolver(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 |
Methods
| Improve this Doc View SourceResolveService<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 |
| System.ArgumentException | If the |
Explicit Interface Implementations
| Improve this Doc View SourceIResolvesRule.ResolveRule(Type)
Declaration
object IResolvesRule.ResolveRule(Type ruleType)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Type | ruleType |
Returns
| Type | Description |
|---|---|
| System.Object |