You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fully qualify type names for services when resolving in RequestDelegateGenerator (#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
Copy file name to clipboardExpand all lines: src/Http/Http.Extensions/test/RequestDelegateGenerator/Baselines/MapAction_ExplicitServiceParam_SimpleReturn_Snapshot.generated.txt
var svc_local = httpContext.RequestServices.GetRequiredService<System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
210
+
var svc_local = httpContext.RequestServices.GetRequiredService<global::System.Collections.Generic.IEnumerable<global::Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
var svc_local = httpContext.RequestServices.GetRequiredService<System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
233
+
var svc_local = httpContext.RequestServices.GetRequiredService<global::System.Collections.Generic.IEnumerable<global::Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
var svcs_local = httpContext.RequestServices.GetRequiredService<System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
313
+
var svcs_local = httpContext.RequestServices.GetRequiredService<global::System.Collections.Generic.IEnumerable<global::Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
var svcs_local = httpContext.RequestServices.GetRequiredService<System.Collections.Generic.IEnumerable<Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
338
+
var svcs_local = httpContext.RequestServices.GetRequiredService<global::System.Collections.Generic.IEnumerable<global::Microsoft.AspNetCore.Http.Generators.Tests.TestService>>();
@@ -225,6 +226,32 @@ public async Task ThrowsIfDiContainerDoesNotSupportKeyedServices()
225
226
Assert.Equal("Unable to resolve service referenced by FromKeyedServicesAttribute. The service provider doesn't support keyed services.",exception.Message);
0 commit comments