Mediator
Mediator copied to clipboard
Support multiple project
Mediator seems not supporting multiple projects. I Have several projects - WebAPI, User, Company. I have mediator installed and correct setup in User and Company. Running those, only the first project registered in DI works.
serviceCollection.AddCompanyServices(); serviceCollection.AddUserServices(); = Company works correctly, User gets error "No handler registered for message type:"
serviceCollection.AddUserServices(); serviceCollection.AddCompanyServices(); = User works correctly, Company gets error "No handler registered for message type:"
I'm not sure what's going on here, could you describe in a little more detail how the project is laid out? In terms of project references and Mediator package references
We have a couple of samples where multiple projects are used, such as this one. Maybe that will help in debugging?
Thank you for a quick response. I have made a solution that is vertically sliced. I have several projects:
Company User WebAPI
There are more, but I want to keep it simple, Company and User are class libraries. Each project has its own Context. WebAPI are almost empty, besides from DI and other code that is needed. Controllers are in respective class library there they belong. In each class library, I have added mediator and implemented it just as you have in your documentation.
But when I run the application, only the first class library called in DI works. If I call Company first, it will work fine, but User will not work ("No handler registered for message type:"). If I have User first in my DI, it will work vine, but Company will not work ("No handler registered for message type:").
I have tried to move DI registration to the WebAPI project, but I will get ambigious reference, as it should. When I register it in each class library, I get the error I mentioned. My guess that it will only allow one registration in DI.
My guess that it will only allow one registration in DI.
Yes that sounds right, we can't have several IMediator implementations in the same DI container.
tracking some improvements around multiple projects here: #97
So there is no way to have commands and queries in different projects registered? I have a situation and project structured as described by @Dotnetstore
this one
I've tried this but the weird thing is if you isolate the sample projects and add the Mediator references as NuGet packages the problem @Dotnetstore describes is still present.
So there is no way to have commands and queries in different projects registered?
You can have commands and queries in different projects, but you can have only one Mediator implementation. So for the project that your running, there can only be one Mediator.SourceGenerator in the dependy graph, otherwise multiple implementations are generated and so which one should the DI container hand you when you ask for IMediator
I've tried this but the weird thing is if you isolate the sample projects and add the Mediator references as NuGet packages the problem @Dotnetstore describes is still present.
I'll try to reproduce this with the multi-project samples.