❔ How explicitly define command and handlers for MediatR
I have my commands and handlers in a different project, and i dont want to include mediatr as a package
14 Replies
the different project should expose a public method for adding dependencies to service collection.
in the other project, which doesn't know about mediator, you add the dependencies.
now the question is how would you send commands to mediator, not knowing MediatR types.
you library which knows about MediatR should also expose interface and a concrete type as dependency, to act as a proxy - because you don't want to inject IMediator I assume
i thought maybe, the side (my infrastructure) with mediatR, i could explicitly define the commands and handlers so it doesnt have to figure it out itself from the interfaces
oh damn i'm such a nooooob
services.AddScoped<IRequestHandler<MyCommand, Unit>, MyCommandHandler>();
i can just register it like so 🤦
but... hrm.. still
i just hate that i have to install the mediatr dependency in my application layer
I would use per the MediatR docs
also, you don't need to use Unit anymore
GitHub
GitHub - jbogard/MediatR: Simple, unambitious mediator implementati...
Simple, unambitious mediator implementation in .NET - GitHub - jbogard/MediatR: Simple, unambitious mediator implementation in .NET
But i still have to use the marker interfaces for mediator yeah?
yes
Yeah kinda was trying to avoid that, my application layer has no dependencies except on the domain
I might just ditch mediatr
there's a contracts-only package for that
Aye i tried that, ill try thay again
or you could stop hurting yourself just to appease the onion arch gods
But its so beautiful when it has no dependencies
onion arch falls apart when it comes into contact with this thing called reality
because you can't actually reasonably split things into neat boxes
This is ddd, its all good, layered yeah, and hexagonal
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.