Skip to content

Simple samples for dummies #1967

Answered by martincostello
Berad asked this question in Q&A
Discussion options

You must be logged in to vote

For your use case it looks like you want a fallback strategy with something similar to:

var options = new FallbackStrategyOptions<MyCustomType>
{
    ShouldHandle = new PredicateBuilder<MyCustomType>().Handle<Exception>(),
    FallbackAction = static args => Outcome.FromResultAsValueTask((MyCustomType)null)
};

var pipeline = new ResiliencePipelineBuilder<MyCustomType>().AddFallback(options);

MyCustomType myValue = pipeline.ExecuteAsync<MyCustomType>(
    token => dbContext.TryGetMyValueByIdAsync(id, token));

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Berad
Comment options

Answer selected by Berad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants