Simple samples for dummies #1967
-
Hi there! In my case I need to retry getting some value from my database, i.e. now I have
where
I don't need to get any exceptions, I just want to retry to get a value several times and if it's null -- ok, I will deal with it. Could you please help me with that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
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)); |
Beta Was this translation helpful? Give feedback.
For your use case it looks like you want a fallback strategy with something similar to: