-
-
Notifications
You must be signed in to change notification settings - Fork 748
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
Property provider factory #1180
Property provider factory #1180
Conversation
… CustomAttributePropertyProvider
This is a big PR and will need some time to review. |
One initial thought here is that this seems quite complicated. Why do we need more than the method name as per #1150? |
It's so that consumers of the library can grow its functionality to support their use cases without being blocked on anyone. Also means Refit itself doesn't have to have too strong am opinion of its own on what winds up in the request properties. And it's done in a way that's composible such that consumers of the library don't have to accept or reject the default opinion, but can instead choose to augment it, or replace it. Personally, I myself don't have a need for the method info, but can definitely see use cases others might have around that. I'm most excited about and in need of flowing data from custom attributes into the request properties as that opens a very powerful extension point that allows for pretty much anything. Which is what #1156 is about. |
Hey @james-s-tayler, while it's super clear that you've done a ton of work on this and definitely crossed the i's and dotted the t's, I think the design of this change is Too Complicated. It has breaking changes (changing the base class of an exception, moving types to other namespaces), and overall it introduces too much complexity / new Concepts. I think that we should start instead with directly implementing this comment from #1150:
Let's do this First, then see what scenarios are still painful to do and think about how to solve them. Parsing string URLs might not be as Elegant as a fancy MethodInfo and Provider setup but like, nearly everyone given the URL and Method will be like "I understand what to do next to Solve My Business Problem (even if it's writing a bunch of ifs and Regexes)". |
My business problem is I want to be able to configure Polly without needing to add an argument to the method. For example:
|
@anaisbetts The design is targeted more at solving #1156. I've had plenty of uses for this in the past. @lostincomputer mentions one particular case, but there are others... Perhaps you have a versioned API and want to be able to do something like:
Or maybe you simply want a declarative way to output messages under certain conditions on certain endpoints
Could probably support #163 too by something like
These particular use cases aren't something Refit would likely want to directly support, I feel like solving just #1150 doesn't help with that while at the same time making Refit I've read through several hundred issues raised on this repo and one of the overall themes that seems to repeat is certain parts of Refit not being extensible enough and users getting blocked. In terms of breaking changes... Yeah I wasn't 100% sure about that. I think it's just shifting DefaultApiExceptionFactory into its own class and a different namespace. I can certainly update the PR and undo that particular change. Though I was brave enough to try it since its is the default ExceptionFactory configured internally by RefitSettings it's probably not actually a breaking change to any consumers of the library, as no one would/should actually have any need to be referencing it directly, and was considering to do some work on Anyway, sorry for the essay, appreciate the review and would love to hear if you have any alternative suggestions on a design that can meet the needs I've outlined here. I hope I can convince you this design, though seemingly complicated, does have its merits! |
This would be awesome.
This could be easily simplified to this:
|
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?
This is a new feature that extends/enhances the work done around the
[Property]
attribute.It adds the notion of a
PropertyProvider
which allows adding properties intoHttpRequestMessage.Properties
on every request without explicitly having to pass in a
[Property]
attribute but instead using information derivedfrom the
MethodInfo
of the currently executing method on the Refit instance, as well as theType
of the Refit target interface.PropertyProviderFactory
allows you to build aList<PropertyProvider>
to populateRefitSettings.PropertyProviders
andcomes with built-in support for common scenarios such as adding the refit target interface type, the method info, and any custom attributes into the
HttpRequestMessage.Properties
.Users can write their own
PropertyProvider
implementations by simply implementing thePropertyProvider
interface and passing into thePropertyProviderFactory
when configuringRefitSettings.PropertyProviders
.What is the current behavior?
The current behavior is you can only pass
[Property]
attributes as part of the method signature.Community feedback on the
[Property]
feature seems to indicate the ability to pass properties is somethinguseful, but the current functionality doesn't quite support some great use cases.
See #1156 and #1150
What is the new behavior?
Users can leverage the new
PropertyProvider
implementation as well as write their own in order to extend the functionality of Refit via passing state toHttpClient
middleware.What might this PR break?
It touches a core part of
HttpRequestBuilderImplementation
as such it has been programmed defensively, so as not to blow up if anything goes wrong with a user provided implementation ofPropertyProvider
. It has a fairly extensive set of tests that include this scenario too to ensure the request can still succeed.Please check if the PR fulfills these requirements
Other information:
This PR introduces a new namespace
Refit.Extensions
to aide in discoverability. It also shifts the existingExceptionFactory
stuff into that namespace. I hope that's not too invasive. If there's any changes you'd rather see backed out in that area, just let me know.