Class AsyncPolicyBase<TModel, TMetadata>
- Namespace
- Motiv
- Assembly
- Motiv.dll
The base class for asynchronous policies. A policy is a specification that resolves to a single value — one assertion or one metadata object per evaluation. Mirrors PolicyBase<TModel, TMetadata>.
public abstract class AsyncPolicyBase<TModel, TMetadata> : AsyncSpecBase<TModel, TMetadata>
Type Parameters
TModelThe model type that the policy will evaluate against
TMetadataThe type of the metadata to associate with the predicate
- Inheritance
-
AsyncSpecBase<TModel>AsyncSpecBase<TModel, TMetadata>AsyncPolicyBase<TModel, TMetadata>
- Inherited Members
- Extension Methods
Methods
EvaluateAsync(TModel, CancellationToken)
Asynchronously evaluates the policy against the model and returns a result that contains the Boolean result of the predicate in addition to a single metadata value.
public Task<PolicyResultBase<TMetadata>> EvaluateAsync(TModel model, CancellationToken cancellationToken = default)
Parameters
modelTModelThe model to evaluate the policy against.
cancellationTokenCancellationTokenA token that can cancel the evaluation.
Returns
- Task<PolicyResultBase<TMetadata>>
A result that contains the Boolean result of the predicate in addition to the metadata.
EvaluatePolicyAsync(TModel, CancellationToken)
Asynchronously evaluates the policy against the model.
protected abstract Task<PolicyResultBase<TMetadata>> EvaluatePolicyAsync(TModel model, CancellationToken cancellationToken)
Parameters
modelTModelThe model to evaluate the policy against.
cancellationTokenCancellationTokenA token that can cancel the evaluation.
Returns
- Task<PolicyResultBase<TMetadata>>
A result that contains the Boolean result of the predicate in addition to the metadata.
EvaluateSpecAsync(TModel, CancellationToken)
Asynchronously evaluates the specification against the model and returns a result that contains the Boolean result of the predicate in addition to the metadata.
protected override Task<BooleanResultBase<TMetadata>> EvaluateSpecAsync(TModel model, CancellationToken cancellationToken)
Parameters
modelTModelThe model to evaluate the specification against.
cancellationTokenCancellationTokenA token that can cancel the evaluation.
Returns
- Task<BooleanResultBase<TMetadata>>
A result that contains the Boolean result of the predicate in addition to the metadata.
Not()
Negates this policy.
public AsyncPolicyBase<TModel, TMetadata> Not()
Returns
- AsyncPolicyBase<TModel, TMetadata>
A new policy that represents the logical NOT of this policy.
OrElse(AsyncPolicyBase<TModel, TMetadata>)
Combines this policy with another policy using the conditional OR operator, preserving the policy
guarantee. The right operand is only evaluated if the left operand resolves to false.
public AsyncPolicyBase<TModel, TMetadata> OrElse(AsyncPolicyBase<TModel, TMetadata> alternative)
Parameters
alternativeAsyncPolicyBase<TModel, TMetadata>The fallback policy.
Returns
- AsyncPolicyBase<TModel, TMetadata>
A new policy that represents the conditional OR of this policy and the alternative.
OrElse(PolicyBase<TModel, TMetadata>)
Combines this policy with a synchronous policy using the conditional OR operator, preserving the
policy guarantee. The synchronous alternative is lifted into the asynchronous hierarchy via
ToAsyncSpec(). The right operand is only evaluated if the
left operand resolves to false.
public AsyncPolicyBase<TModel, TMetadata> OrElse(PolicyBase<TModel, TMetadata> alternative)
Parameters
alternativePolicyBase<TModel, TMetadata>The synchronous fallback policy.
Returns
- AsyncPolicyBase<TModel, TMetadata>
A new policy that represents the conditional OR of this policy and the alternative.
Operators
operator !(AsyncPolicyBase<TModel, TMetadata>)
Negates a policy.
public static AsyncPolicyBase<TModel, TMetadata> operator !(AsyncPolicyBase<TModel, TMetadata> policy)
Parameters
policyAsyncPolicyBase<TModel, TMetadata>The policy to negate.
Returns
- AsyncPolicyBase<TModel, TMetadata>
A new policy that represents the logical NOT of the policy.