question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error when using MediatR with NetCore's new Worker service

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:17 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
lilasquaredcommented, Dec 2, 2019

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

0reactions
mattkrebscommented, Dec 3, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found