jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
10.84k stars 1.15k forks source link

Can't register MediatR in WorkerService project #985

Closed longvietcode closed 6 months ago

longvietcode commented 6 months ago

.NET version: 8.0 MediatR version: 12.2.0

So I went into this error while trying to register MedaitR with the DI in my WorkerService project image

This is the Program file in my WorkerService project and my Solution hierarchy: image image

The location of the CQS implementation that I need to use: image

The location that I need to use it: image

This is how I inject it: image

How can I resolve this error, thanks!

jbogard commented 6 months ago

Don't inject your mediator, you should resolve from the service scope just like your DbContext. And it looks like it's not MediatR that's the problem, it's the dependencies of that handler that can't be resolved. The exception description tells you exactly what dependency can't be resolved.