-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Add support for DI in Hub methods #34047
Conversation
85fd264
to
d0f7c41
Compare
This is jank and it should work for any number of arguments even though 32 is insane. 64? 😄 |
Changing the field to |
Sounds reasonable. I don't think allocating a |
/// <remarks> | ||
/// Disabled by default. | ||
/// </remarks> | ||
public bool EnableInferredFromServiceParameters { get; set; } |
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.
I think we should infer service parameters by default. I'd be tempted to remove this option altogether. How many service types are also serializable? I see wanting an option to opt-out though since there isn't another escape hatch I can see if you happen to have an argument type registered as a service.
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.
I see wanting an option to opt-out though since there isn't another escape hatch I can see if you happen to have an argument type registered as a service.
This is my main concern, which is why I switched the whole PR to using IFromServiceMetadata
and then having an opt-in for inferring.
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.
Lets do an opt-out then.
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.
I'm going to leave as opt-in for now, we can discuss in chat and/or API review
Thank you for your API proposal. I'm removing the |
Thank you for your API proposal. I'm removing the |
@davidfowl @halter73 This should be ready for final review, updated to be opt out and use the API approved name. |
Co-authored-by: Stephen Halter <halter73@gmail.com>
Fixes #16686
The issue talks about having a[FromServices]
attribute, that isn't addressed in the current form of this PR.Using
IFromServiceMetadata
like we do for Minimal APIs to check if a parameter should be resolved from a service. This makes the feature opt-in and less likely for us to accidentally mess something up.Source generator wont be able to do anything special about hub methods with services, but that might just be something we don't care about and developers should design their interfaces with that in mind.
Currently using a mask (ulong) to store indices for service positions in Hub methods which limits hub methods to 64 arguments, I think this is fine though 😄
API
public class HubOptions { + public bool DisableImplicitFromServiceParameters { get; set; } }