Mediator
Mediator copied to clipboard
Mediator only adds classes from one assembly
I'm in the process of migrating from Mediatr to Mediator (2.0.27-rc). My solution is setup like this:
- WebApi (Controllers that send/publish queries and commands)
- Application (Defines commands, queries and handlers e.g.
GetItemQuery
,CreateItemCommand
,GetItemQueryHandler
) - Domain (Domain logic and events e.g.
ItemCreated
) - Infrastructure (storage logic and publishing of Domain Events)
Using Mediatr, I added the relevant classes to the DI containers like this:
services.AddMediatr(applicationAssembly)
;
services.AddMediatr(infrastructureAssembly)
;
However, with Mediator it doesn't seem to matter where I add the .AddMediator
call - it only ever seems to generate code that includes Domain Events defined in the Domain project (ItemCreated
etc). I've also tried adding [assembly: MediatorOptions]
to each project to no avail.
What am I doing wrong? How do I define which assemblies Mediator should scan for queries, commands and handlers?
The project where you have installed the source generator package will scan and generate project based on all referenced projects. Your setup sounds pretty similar to the clean architecture sample located here: https://github.com/martinothamar/Mediator/tree/main/samples/ASPNET_CleanArchitecture
Is that correct? In that case maybe you can see if there is a difference in setup here that leads to the issue?
If the sourcegen package is installed in WebApi, and WebApi references Application, then you should be able to use the GetItemQuery
message from the controllers in WebApi for example
It turns out I had a version mismatch in one of the packages. Sorted that out and it's working now. Closing this issue, thanks for the help!
I'm getting this error message: No handler registered for message type: (...).DownloadDocumentQuery"
I have a query defined in the Application project, and its handler in the Infrastructure project layer. If handler is also in the same assembly (Application) then it works fine.