C
C#14mo 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
jalepi14mo 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
dave114mo 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
jcotton4214mo 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
jcotton4214mo 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
dave114mo ago
But i still have to use the marker interfaces for mediator yeah?
jcotton42
jcotton4214mo ago
yes
dave1
dave114mo ago
Yeah kinda was trying to avoid that, my application layer has no dependencies except on the domain I might just ditch mediatr
jcotton42
jcotton4214mo ago
there's a contracts-only package for that
dave1
dave114mo ago
Aye i tried that, ill try thay again
jcotton42
jcotton4214mo ago
or you could stop hurting yourself just to appease the onion arch gods
dave1
dave114mo ago
But its so beautiful when it has no dependencies
jcotton42
jcotton4214mo 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
dave114mo ago
This is ddd, its all good, layered yeah, and hexagonal
Accord
Accord14mo 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
More Posts
❔ I'm trying to implement a search function using LINQhttps://paste.mod.gg/gctsykkoclwi/3 ```cs public void SearchBook() // Defining a method and use it ❔ Blazor external loginHi folks, I'm working with a Blazor Server project, where I am using Identity for inbuilt account r❔ ASP.NET Core, OrchardCore, OrchardCMSI am starting to lose it, I've been following the tutorials of the OrchardCore documentation to add ❔ ✅ ASP.NET Core - Implementing an API in CQRS patternHey everyone, I am trying to make API integration to my ASP.NET Core app. I did something but I am n❔ Unable to process post request with asp.net coreI am making use of a document processing component (https://ej2.syncfusion.com/react/documentation/d❔ Socket connection in WPF applicationHello, I'm fairly new to the C# environment and there's something I can't figure out: I created a co❔ Force log out the user after account deletion with JWT bearer auth.Hello, I'm working on adding a feature that allows administrators to delete users. As things current✅ I updated to .NET 8 and now it broke...Hello i thought about .NET 8 and it has very usefull features so i want to update to it but sadly wh✅ Compiling ASP.NET 7 app using Github ActionsI am trying to compile my ASP.NET 7 application solution using Github actions but am getting the fol❔ How to handle a group of variables that need to stay together within a class?How should I handle a group of data that needs to stay together within a class? The data is a set of