Mediator icon indicating copy to clipboard operation
Mediator copied to clipboard

Mediator only adds classes from one assembly

Open saliej opened this issue 1 year ago • 1 comments

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?

saliej avatar Nov 08 '22 11:11 saliej

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

martinothamar avatar Nov 09 '22 14:11 martinothamar

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!

saliej avatar Nov 10 '22 07:11 saliej