Show / Hide Table of Contents

Class MessageProviderFactoryStrategyProvider

A strategy-selector/factory class which gets the appropriate strategy implementation for getting a failure message provider implementation for a specified message provider type and rule interface.

Inheritance
System.Object
MessageProviderFactoryStrategyProvider
Implements
IGetsMessageProviderFactoryStrategy
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.Messages
Assembly: CSF.Validation.dll
Syntax
public class MessageProviderFactoryStrategyProvider : IGetsMessageProviderFactoryStrategy

Constructors

| Improve this Doc View Source

MessageProviderFactoryStrategyProvider(IServiceProvider)

Initialises a new instance of MessageProviderFactoryStrategyProvider.

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

A service provider.

Exceptions
Type Condition
System.ArgumentNullException

If the serviceProvider is null.

Methods

| Improve this Doc View Source

GetMessageProviderFactory(MessageProviderTypeInfo, Type)

Gets a message provider factory which is appropriate for the specified provider type and rule interface.

Declaration
public IGetsNonGenericMessageProvider GetMessageProviderFactory(MessageProviderTypeInfo messageProviderTypeInfo, Type ruleInterface)
Parameters
Type Name Description
MessageProviderTypeInfo messageProviderTypeInfo

The candidate message provider type.

System.Type ruleInterface

The interface used for the validation rule.

Returns
Type Description
IGetsNonGenericMessageProvider
Remarks

This method will examine the message provider interfaces which are implemented by the ProviderTypeInfo of the messageProviderTypeInfo. Specifically it will consider all implementations of any of:

  1. IGetsFailureMessage<TValidated, TParent>
  2. IGetsFailureMessage<TValidated>
  3. IGetsFailureMessage

It will then return a message-provider-factory strategy implementation which best-matches the interfaces indicated by the messageProviderTypeInfo, based upon the actual validation rule interface which is in-use: ruleInterface.

This 'matching' process will look for matches in the order the message provider interfaces are listed above. For example, if a message provider implements the interface with two generic types, and for types that are compatible with the generic types present upon the rule interface, then the double-generic strategy will be given preference over a single-generic strategy. This is true even if the message provider type also implements a single-generic message provider interface that is compatible with the rule interface.

Obviously, if the message provider type implements the non-generic IGetsFailureMessage then this will match every possible rule interface, as it is non-generic. This behaviour may be leveraged as a fall-back option for unexpected scenarios (such as validating Errored results).

If this method cannot find any suitable strategy for getting a message provider - the provider type indicated by messageProviderTypeInfo does not implement any interface which is compatible with the ruleInterface - then it will return null. This means that no factory strategy is applicable and that the provider type is not compatible with the rule interface.

Exceptions
Type Condition
System.ArgumentNullException

If any parameter is null.

Implements

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