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
Support resolving keyed services from DI in RDF and RDG #50093
Conversation
9c233cb
to
95c58d7
Compare
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 changes in these text files are all related to the fact that we've added a Microsoft.Extensions.DependencyInjection
using to the test script so the intercept line numbers changed. It's immaterial to the change here.
@@ -139,6 +139,12 @@ private void ProcessEndpointParameterSource(Endpoint endpoint, ISymbol symbol, I | |||
{ | |||
Source = EndpointParameterSource.Service; | |||
} | |||
else if (attributes.TryGetAttribute(wellKnownTypes.Get(WellKnownType.Microsoft_Extensions_DependencyInjection_FromKeyedServicesAttribute), out var keyedServicesAttribute)) |
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.
Does this work with derived types?
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.
Are you referring to if the user is using a derived version of FromKeyedServices
attribute? If so, the answer is no but not sure that is a scenario we want to support?
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.
That is what I'm referring to. The type is unsealed by design I believe.
public async Task SupportsSingleKeyedServiceWithPrimitiveKeyTypes(object key) | ||
{ | ||
var source = $$""" | ||
app.MapGet("/", (HttpContext context, [FromKeyedServices({{key.ToString()?.ToLowerInvariant()}})] TestService arg) => context.Items["arg"] = arg); |
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.
Does this work? The key is a string
but the keyed service is added with object
.
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 key here is actually an object. The ToString()?.ToLowerVariant()
here is to get it to emit the write code for the false
value. The source code snippet ends up having [FromKeyedServices(false)]
, [FromKeyedServices(12.3)]
, etc.
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.
Ok, stringed code is odd looking 😃
Closing so I can cherry-pick and retarget to 8.0-rc1. See #50095. |
Addresses #49633