You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Mediator on the same project with MassTransit I get the following error:
System.Exception: 'Invalid configuration detected for Mediator. Generated code for 'Singleton' lifetime, but got 'Scoped' lifetime from options. This means that the source generator hasn't seen the 'AddMediator' method call during compilation. Make sure that the 'AddMediator' method is called from the project that references the Mediator.SourceGenerator package.'
If I remove the MassTransit package and service registrations it all works just fine.
It only occurs in mediator 3.0.0-preview.X. If I downgrade to version 2.0.* the error does not happen.
EDIT: On version 2.1.6 also gives the same error
Thanks in advance!
The text was updated successfully, but these errors were encountered:
I loaded Mediator.SourceGenerator and Mediator.Abstractions libraries into the API project and also the Mediator.Abstractions library into the project where commands and queries are located.
MassTransit consumers should be housed within the application layer in a clean architecture or onion architecture system.
Therefore you can relocate the call to the (services.AddMassTransit(...) method to the public static AddApplication(...) method in your Application layer's assembly.
Remember that in that project you only need to have package references for Mediator.Abstractions as well as MassTransit.RabbitMQ or MassTransit.AmazonSQS.
Meanwhile you need to have a package reference to Mediator.SourceGenerator in the presentation layer application.
You also need to remove all package references to MassTransit libraries within the presentation layer application and most importantly remove all lines which say 'using MassTransit;'
It's likely that the configuration delegate passed to the services.AddMassTransit method will need to obtain values from the application settings or from environment variables. Therefore you might have to pass an additional Microsoft.Extensions.DependencyInjection.IConfiguration parameter to your AddApplication method.
Because writing the configuration delegate can take a lot of code, you may choose to create a dedicated MassTransitInstaller public static class.
Last of all I want to acknowledge that the foregoing is only a work-around and so it's right that this issue is kept open because my instructions will not work if somebody is building a monolithic application.
When using Mediator on the same project with MassTransit I get the following error:
If I remove the MassTransit package and service registrations it all works just fine.
It only occurs in mediator
3.0.0-preview.X
. If I downgrade to version2.0.*
the error does not happen.EDIT: On version 2.1.6 also gives the same error
Thanks in advance!
The text was updated successfully, but these errors were encountered: