-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document outcome strategy anti-patterns #1994
Document outcome strategy anti-patterns #1994
Conversation
* deprecates AddException API in the OutcomeGenerator
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1994 +/- ##
==========================================
+ Coverage 83.64% 83.67% +0.02%
==========================================
Files 312 312
Lines 7105 7105
Branches 1054 1054
==========================================
+ Hits 5943 5945 +2
Misses 789 789
+ Partials 373 371 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Hi @martincostello @peter-csala I just addressed the rest of the feedback, please take a look again when you guys have the chance. |
@@ -82,7 +85,7 @@ public static void OutcomeGenerator() | |||
OutcomeGenerator = new OutcomeGenerator<HttpResponseMessage>() | |||
.AddResult(() => new HttpResponseMessage(HttpStatusCode.InternalServerError)) // Result generator | |||
.AddResult(() => new HttpResponseMessage(HttpStatusCode.TooManyRequests), weight: 50) // Result generator with weight | |||
.AddResult(context => CreateResultFromContext(context)) // Access the ResilienceContext to create result | |||
.AddResult(context => new HttpResponseMessage(CreateResultFromContext(context))) // Access the ResilienceContext to create result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage samples advocate to use one of the anti-patterns
...
.AddResult(context => new HttpResponseMessage(CreateResultFromContext(context))) // Access the ResilienceContext to create result
.AddException<HttpRequestException>(), // You can also register exceptions
Please update these OutcomeGenerator
s by removing theAddException
clauses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I originally opened the PR I had removed those guys since I had deprecated it, however, I put them back so that we support that scenario (injecting results and exceptions in the same strategy) but under their judgment after knowing the caveats/side effects explained in the anti-pattern sections and in the footer. I can remove that entirely from the docs but it would be hidden. Honestly, while I understand it is handy it feels like we're kinda discouraging people to use the right strategy to inject faults.
We could also add a comment in the samples as I did in some snippets, like this: //
and maybe add a remarks
on the API pointing to the docs? thoughts?
@martincostello I think this PR is ready to go BTW. |
Yep, I'm just AFK a lot at the moment and haven't had the chance to re-review properly. It's in my todo queue. |
Pull Request
The issue or feature being addressed
AddException
API in theOutcomeGenerator
Details on the issue fix or feature implementation
As per our discussion here we decided to document why injecting exceptions via the outcome strategy is an anti-pattern (in advanced scenarios when the usage of delegates is required):
As part of this change, I marked the
AddException
API in theOutcomeGenerator
as deprecated to be consistent with what we're preaching, it does not make sense to say it is an anti-pattern and at the same time provide a built-in way to do so + if we expose an API to inject an exception as an outcome why have the fault strategy at all? why consumers would use it? or when to use one or another? it ends up creating confusion.Confirm the following