-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fully qualify type names for services when resolving in RequestDelegateGenerator #58640
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
Fully qualify type names for services when resolving in RequestDelegateGenerator #58640
Conversation
These two places correspond to resolution of a service from DI when
attributed with `FromServicesAttribute` or with
`FromKeyedServicesAttribute`. When the type name of the service is not
fully qualified, the generator can generate code which fails to compile.
For example, given a service `ExampleService` in namespace `Http`, the
generator can generate code to resolve an instance of such a service
like this:
```c#
var e_local = httpContext.RequestServices.GetRequiredKeyedService<Http.ExampleService>("example");
```
…but `Microsoft.AspNetCore.Http` is a nearer match for the reference to
"Http", so the compiler will look for a type
`Microsoft.AspNetCore.Http.ExampleService` (which doesn't exist – at
least, not at time of writing), and compilation will fail.
Fixes: dotnet#58633
captainsafia
left a comment
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.
Thanks for opening a PR for this! I left one recommendation inline.
Also -- any chance we can add test coverage for this?
src/Http/Http.Extensions/gen/StaticRouteHandlerModel/Emitters/EndpointParameterEmitter.cs
Outdated
Show resolved
Hide resolved
captainsafia
left a comment
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.
Looks good overall! Left one small comment about a possibly unneeded using in the base class for tests.
src/Http/Http.Extensions/test/RequestDelegateGenerator/RequestDelegateCreationTestBase.cs
Show resolved
Hide resolved
|
The failures here look unrelated. Is there a way to kick the build off again, or is this waiting for something? |
Our builds can be flakey sometimes. I've just kicked it to hopefully get this through. 🤞🏽 |
…teGenerator (#58640) * Fully Qualify Type Names When Resolving in RDG These two places correspond to resolution of a service from DI when attributed with `FromServicesAttribute` or with `FromKeyedServicesAttribute`. When the type name of the service is not fully qualified, the generator can generate code which fails to compile. For example, given a service `ExampleService` in namespace `Http`, the generator can generate code to resolve an instance of such a service like this: ```c# var e_local = httpContext.RequestServices.GetRequiredKeyedService<Http.ExampleService>("example"); ``` …but `Microsoft.AspNetCore.Http` is a nearer match for the reference to "Http", so the compiler will look for a type `Microsoft.AspNetCore.Http.ExampleService` (which doesn't exist – at least, not at time of writing), and compilation will fail. Fixes: #58633 * Correct Symbol Display Format and Add Tests See: #58633
Fully Qualify Type Names When Resolving in RDG
These two places correspond to resolution of a service from DI when attributed with
FromServicesAttributeor withFromKeyedServicesAttribute. When the type name of the service is not fully qualified, the generator can generate code which fails to compile.Description
For example, given a service
ExampleServicein namespaceHttp, the generator can generate code to resolve an instance of such a service like this:…but
Microsoft.AspNetCore.Httpis a nearer match for the reference to "Http", so the compiler will look for a typeMicrosoft.AspNetCore.Http.ExampleService(which doesn't exist – at least, not at time of writing), and compilation will fail.Fixes #58633