-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I am trying to inject a service into a hub method using Dependency Injection (DI). I have explicitly specified the [FromServices] attribute before the parameter that should be resolved from DI in the hub method.
Currently, I have multiple hub methods that start with a service parameter. Recently, I encountered an issue with such an arrangement. When I pass a null value for the parameter following the service parameter, the service parameter fails to resolve its dependency.
It seems that the hub method is trying to resolve dependencies from both the client message and the DI container. Consequently, placing the injecting parameter first may lead to improper binding of the null value.
I also tried using the DisableImplicitFromServicesParameters option, but the same issue persists.
Then, I tried placing the service parameter last, and it worked fine.
Expected Behavior
When explicitly marked with the [FromServices] attribute, the service parameter should reliably resolve its dependency from the Dependency Injection (DI) container, regardless of the order of parameters in the hub method.
Steps To Reproduce
- Clone the sample project repository from https://github.com/pranjalg-dew/AspNetCore-SignalR-BugRepro.
- Build and run the project locally.
- Open the web page hosted in the repository which can send values to the SignalR endpoint.
- Keep textbox empty and click on send message button.
- Observe the resolution of the
[FromServices] IMyService serviceparameter. Note that the service parameter is null.
Exceptions (if any)
No response
.NET Version
No response
Anything else?
No response