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
{{ message }}
Repository navigation
AddHostedService does not register specified Type Parameter in DI container #53831
classFooService:IHostedService{publicFooService(){}/* ... */}classBarService:IHostedService{publicBarService(FooServicefoo){}/* ... */}services.AddHostedService<FooService>();// worksservices.AddHostedService<BarService>();// crashes when because DI container does not find FooService
The issue is quite straight forward in the .NET source code because the THostedService is not registered but instead a IHostedService ...
My expectation was clearly, that the type I register with a ServiceCollection.Add* function later can be retrieved. I lost several hours due to this until I found the answer somewhere on StackOverflow.
Configuration
.NET 5
OS/Arch: Does not matter
Regression?
No
Other information
If the vote is not to double register the service (I assume the IHostedService is needed for the host logic), I would at least propose to add a warning in the documentation and maybe the function inline documentation.
Triage: Given lower interest (2 people in 5 years) + there is simple workaround, we do not think we should add new API -- that is an overkill for a niche scenario.
We could improve documentaiton. @cincuranet will look at it.
Activity
tthiery commentedon Jan 20, 2026
This is a human generated activity to keep it alive 😃
karelz commentedon Jan 21, 2026
Triage: Given lower interest (2 people in 5 years) + there is simple workaround, we do not think we should add new API -- that is an overkill for a niche scenario.
We could improve documentaiton. @cincuranet will look at it.
Update documentation for AddHostedService. (dotnet#123658)
Update documentation for AddHostedService. (dotnet#123658)