C
C#2y ago
dave1

❔ 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
jalepi
jalepi2y ago
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
dave1
dave1OP2y ago
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
jcotton42
jcotton422y ago
I would use
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<Startup>());
services.AddMediatR(cfg => cfg.RegisterServicesFromAssemblyContaining<Startup>());
per the MediatR docs also, you don't need to use Unit anymore
jcotton42
jcotton422y ago
GitHub
GitHub - jbogard/MediatR: Simple, unambitious mediator implementati...
Simple, unambitious mediator implementation in .NET - GitHub - jbogard/MediatR: Simple, unambitious mediator implementation in .NET
dave1
dave1OP2y ago
But i still have to use the marker interfaces for mediator yeah?
jcotton42
jcotton422y ago
yes
dave1
dave1OP2y ago
Yeah kinda was trying to avoid that, my application layer has no dependencies except on the domain I might just ditch mediatr
jcotton42
jcotton422y ago
there's a contracts-only package for that
dave1
dave1OP2y ago
Aye i tried that, ill try thay again
jcotton42
jcotton422y ago
or you could stop hurting yourself just to appease the onion arch gods
dave1
dave1OP2y ago
But its so beautiful when it has no dependencies
jcotton42
jcotton422y ago
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
dave1
dave1OP2y ago
This is ddd, its all good, layered yeah, and hexagonal
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server