-
-
Notifications
You must be signed in to change notification settings - Fork 746
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
Feature: allow developers to inject the MethodInfo as a Property #1367
Feature: allow developers to inject the MethodInfo as a Property #1367
Conversation
…stMessage.Options
I would love to have this to be able to override services
.AddRefitClient()
.ConfigureHttpClient(httpClient => httpClient.Timeout = TimeSpan.FromSeconds(30)); public class HttpMessageHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var timeoutSeconds = 15; // ToDo: read configuration for operation identified by request.Options[HttpRequestMessageOptions.MethodInfoKey]
using var timeoutTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(timeoutSeconds));
return await base.SendAsync(request, timeoutTokenSource.Token);
}
} |
merge pleeese, I really need this to look up the object type of the method |
@james-s-tayler When dou you plan to merge this pull request? |
@gokhanabatay you'd have to ask @clairernovotny as I don't have merge permissions. The community has been asking for this for many years now, with about 5 different PRs open all aimed at enabling the same thing. I've sort of given up hope that it will ever be merged. Don't really get why either. |
Hi @clairernovotny, We are trying to get executing method with some bad assumptions. I think its a good implementation but I cannot understand why its still waiting to merge. Dou you have any idea what its needed to be done to merge this pull request. I don't know who is in charge so I ask you to discuss with community. @james-s-tayler thank you for quick response, Does community thinks exposing whole method info is a bad idea, if so why interface type already exposed with above method. Maybe exposing current executing method hash code would be enough to get method info inside delegate handler? |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What kind of change does this PR introduce?
A feature to make the
MethodInfo
of the method on the Refit client interface invoked available to handlers via theHttpRequestMessage.Options
/HttpRequestMessage.Properties
.This behavior is opt-in via the
RefitSettings
What is the current behavior?
People either can't do what they want or are implementing workarounds by polluting their interfaces.
There are three existing PRs for this:
RestMethodInfo
available in the request options #1317And a couple of issues:
What is the new behavior?
New behavior is
RefitSettings.InjectMethodInfoAsProperty
defaults tofalse
so Refit as a library remains (mostly) unopinionated about the contents ofHttpRequestMessage.Options
/HttpRequestMessage.Properties
, however if set totrue
it will inject theMethodInfo
intoHttpRequestMessage.Options
/HttpRequestMessage.Properties
under the keyRefit.MethodInfo
.What might this PR break?
Nothing, the behavior is opt-in, so it has to explicitly be enabled giving the developer the chance to consider if there might be any implications for their codebase if the full
MethodInfo
were to be populated into and to put any mitigations necessary should they require it if they do wish to take advantage of the functionality.I fixed up my benchmarks PR #1175 and benchmarked it to compare and found no differences in either execution time or allocations when injecting the
MethodInfo
.net6.0 TaskApiResponseT baseline
net6.0 TaskApiResponseT with MethodInfo added to HttpRequestMessage.Options
Please check if the PR fulfills these requirements
Other information:
I know previously it has been stated that it would be acceptable if we store the method name as a string, but I for one just don't feel comfortable relying on something as critical as an integration point between two systems containing some "stringly typed" behavior when it could be strongly typed. Once someone introduces an overloaded method then all bets are off and it wouldn't surprise me to see that cause a potentially nasty production incident for someone somewhere, and/or future support issues.
I believe this implementation is a good half-way point between simplicity, safety, and usability and sincerely hope we can get this merged.