Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

captainsafia
Copy link
Member

Addresses #49633

@captainsafia captainsafia added feature-rdg area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf and removed area-runtime labels Aug 15, 2023
Copy link
Member Author

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))
Copy link
Member

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?

Copy link
Member Author

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?

Copy link
Member

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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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 😃

@captainsafia captainsafia changed the base branch from main to release/8.0-rc1 August 15, 2023 23:53
@captainsafia captainsafia changed the base branch from release/8.0-rc1 to main August 15, 2023 23:53
@captainsafia
Copy link
Member Author

captainsafia commented Aug 15, 2023

Closing so I can cherry-pick and retarget to 8.0-rc1.

See #50095.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-rdf feature-rdg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants