Error when using MediatR with NetCore's new Worker service
See original GitHub issueI am currently using MediatR successfully with my .net core web project. But unfortunately when using a Worker service the DI breaks and can not find my Handlers. Worker Services require an Environment Var of "DOTNET_ENVIRONMENT" : "Development"
and my web project uses "ASPNETCORE_ENVIRONMENT" : "Development"
when i switch my worker service to use the later of the two EV vars, there are no problems with my worker services finding the Handlers, but the worker services picks up the wrong appsettings.[ENV].json
(Production instead of Development).
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:17 (10 by maintainers)
Top Results From Across the Web
ASP.NET Core MediatR error: Register your handlers with ...
AddMediatR() was the actual issue, after I started registering my dependencies before registering Mediator everything works fine.
Read more >ASP.Net Core API Error (Unable to resolve service for type ' ...
I built a Web API using ASP.Net Core (from Microsoft Tutorial). When calling the API, I got this error below: The error can...
Read more >CQRS with Mediatr and ASP.NET Core - Steve Gordon
An introduction to implementing the CQRS pattern in ASP.NET Core using the Mediatr library.
Read more >You Probably Don't Need to Worry About MediatR : r/dotnet
The Controller takes a dependency on ASP.NET. The Service, where all the domain logic lives, doesn't. That's not a coincidence. We're doing that ......
Read more >Error while validating the service descriptor 'servicetype
Your Worker class (which you haven't shown) takes a direct dependency on a scoped service - presumably the Entity Framework context.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s weird that changing the environment variables cause it to work / not work - does this have any impact? I assume your worker service is what is injecting IMediator, which is scoped by default
Seems like this is not the right thread for all this and it is obviously more of a MS question/issue. I appreciate you both chiming in. I do have it working with creating the scopes “on the fly”.
@lilasquared As to your question about why we need a worker service. There are just some tasks that need to be done when items expire or email need to be sent if say a shopping cart becomes out dated. Things like that.