The second letter in the Hebrew alphabet is the ב bet/beit. Its meaning is "house". In the ancient pictographic Hebrew it was a symbol resembling a tent on a landscape.
Note: Pre-release packages are distributed via feedz.io.
The abstraction library for Bet.Extensions.Resilience Polly.
It provides with easy configuration syntax for Polly policies.
If you like or are using this project to learn or start your solution, please give it a star. Thanks!
dotnet add package Bet.Extensions.Resilience.Abstractions- Add Policies with their Shapes
services.AddPollyPolicy<AsyncTimeoutPolicy, TimeoutPolicyOptions>("TimeoutPolicyOptimistic")
.ConfigurePolicy(
sectionName: PolicyOptionsKeys.TimeoutPolicy,
(policy) =>
{
policy.CreateTimeoutAsync(TimeoutStrategy.Optimistic);
})
.ConfigurePolicy(
sectionName: PolicyOptionsKeys.TimeoutPolicy,
(policy) =>
{
policy.ConfigurePolicy = (options, logger) =>
{
logger.LogInformation("Hello TimeoutPolicyOptimistic");
return Policy.TimeoutAsync(options.Timeout, TimeoutStrategy.Optimistic);
};
},
policyName: "TimeoutPolicyAsync");
services.AddPollyPolicy<AsyncTimeoutPolicy<bool>, TimeoutPolicyOptions>("TimeoutPolicyPessimistic")
.ConfigurePolicy(
sectionName: "DefaultPolicy:TimeoutPolicy",
(policy) =>
{
PolicyShapes.CreateTimeoutAsync<TimeoutPolicyOptions, bool>(policy);
});- Use the Polly policy withing the other components by getting values from the
PolicyBucketregistry.
var policy = host.Services.GetRequiredService<PolicyBucket<AsyncTimeoutPolicy, TimeoutPolicyOptions>>();
var optimisticPolicy = policy.GetPolicy("TimeoutPolicyAsync") as IAsyncPolicy;
var pessimisticPolicy = policy.GetPolicy("TimeoutPolicyPessimistic") as IAsyncPolicy<bool>;- Or using
IPolicyRegistry<string>if the policies are configured for the host
var policyRegistry = host.Services.GetRequiredService<IPolicyRegistry<string>>();
var pessemisticPolicy = host.Services.GetRequiredService<IPolicyRegistry<string>>()
.Get<IAsyncPolicy<bool>>("TimeoutPolicyPessimistic");Policy can be:
- void Async
- void Sunc
- Async
- Sync
Policy can have Options:
- Specific to the policy configuration i.e.
MaxRetries - Configurations provider can raise change event that can be monitored. Upon the change registrations for policies must be updated.
Policy can be registered with:
IPolicyRegistry<string>- Dependency Injection
Policy can combine other policies
WrapAsyncWrap
