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
Implements
Inherited Members
Namespace: CSF.Validation.Messages
Assembly: CSF.Validation.dll
Syntax
public class MessageProviderFactoryStrategyProvider : IGetsMessageProviderFactoryStrategy
Constructors
| Improve this Doc View SourceMessageProviderFactoryStrategyProvider(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 |
Methods
| Improve this Doc View SourceGetMessageProviderFactory(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:
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. |