-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Integrate keyed DI with HttpClientFactory #90272
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,26 @@ public override string? Name | |
} | ||
} | ||
|
||
public override HttpMessageHandler PrimaryHandler { get; set; } = new HttpClientHandler(); | ||
private HttpMessageHandler? _primaryHandler; | ||
internal bool PrimaryHandlerIsSet { get; private set;} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this needed? Why can't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there are existing cases when primary handler is set explicitly to null. E.g. in gRPC. While I kinda consider this pattern erroneous, I still don't want to break the users... |
||
public override HttpMessageHandler PrimaryHandler | ||
{ | ||
get | ||
{ | ||
if (_primaryHandler is null && !PrimaryHandlerIsSet) | ||
{ | ||
_primaryHandler = new HttpClientHandler(); | ||
PrimaryHandlerIsSet = true; | ||
} | ||
return _primaryHandler!; | ||
} | ||
|
||
set | ||
{ | ||
_primaryHandler = value; | ||
PrimaryHandlerIsSet = true; | ||
} | ||
} | ||
|
||
public override IList<DelegatingHandler> AdditionalHandlers { get; } = new List<DelegatingHandler>(); | ||
|
||
|
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.
If you change PrimaryHandlerActions / AdditionalHandlersActions to be
List<T>
instead ofIReadOnlyList<T>
, then you canforeach
these, instead.