Skip to content

Support resolving keyed services from DI in RDF and RDG#50093

Closed
captainsafia wants to merge 1 commit intomainfrom
safia/keyed-di
Closed

Support resolving keyed services from DI in RDF and RDG#50093
captainsafia wants to merge 1 commit intomainfrom
safia/keyed-di

Conversation

@captainsafia
Copy link
Copy Markdown
Contributor

Addresses #49633

@ghost ghost added the area-runtime label Aug 15, 2023
@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
Copy Markdown
Contributor 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.

{
Source = EndpointParameterSource.Service;
}
else if (attributes.TryGetAttribute(wellKnownTypes.Get(WellKnownType.Microsoft_Extensions_DependencyInjection_FromKeyedServicesAttribute), out var keyedServicesAttribute))
Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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 requested review from a team, mkArtakMSFT and wtgodbe as code owners 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
Copy Markdown
Contributor 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.

2 participants