conflict in generated code if imported in multiple projects
See original GitHub issueim unable to use Mediator.SourceGenerator in project, that is referencing different project which is already using Mediator.SourceGenerator - second project will throw at me this message: (CS0436)
Error CS0436 The type 'MediatorDependencyInjectionExtensions' in 'Mediator.SourceGenerator.Roslyn40\Mediator.SourceGenerator.IncrementalMediatorGenerator\Mediator.g.cs' conflicts with the imported type 'MediatorDependencyInjectionExtensions' in 'ProjectA'. Using the type defined in 'Mediator.SourceGenerator.Roslyn40\Mediator.SourceGenerator.IncrementalMediatorGenerator\Mediator.g.cs'.
(technically it is ‘only’ warning, but i have TreatWarningsAsErrors enabled and therefore my build fails… )
affected types:
Mediator.MediatorOptions
Mediator.MediatorOptionsAttribute
Microsoft.Extensions.DependencyInjection.MediatorDependencyInjectionExtensions
ideas how to fix this:
- move
Mediator.MediatorOptionsandMediator.MediatorOptionsAttributetoMediator.Abstractionspackage - they looks like they do not need to be generated - generate
MediatorDependencyInjectionExtensionsin namespace defined byMediatorOptions:Namespaceproperty - this way i can use multiple generated AddMediator() methods
-or-
make all 3 affected classes internal - this will force to call AddMediator method from within project, that generated it but is simple fix
Issue Analytics
- State:
- Created 10 months ago
- Comments:11 (4 by maintainers)

Top Related StackOverflow Question
Ah, ok - yes that does solve the issue I was having - thanks.
It has meant that all my handlers need to be public accessible to the Program though. They are marked as internal, so I have just included an InternalsVisibleTo(Program) in Assembly1 and Assembly2. This is so the generated Mediator can add the services and associated RequestClassHandlerWrapper.
It would be slightly better if I could keep those handlers private within their respective Assemblies. However, it does seem more convenient to have one source generator. It is not a bother for the moment, my project still isn’t big enough to worry too much about these kinds of things.
Thanks again.
hello, sorry for late reply
im experimenting with onion architecture / domain driven developement so my project structure is probably wrong …
im using single DI provided by asp.net core. my host project is basically
program.csfrom aspnet core minimal api template; modules are registered here plan is to have separate modules, that can be enabled in host in random order each module is using mediator internaly for CQRS and exporting extension methods to register itself in host project module may be dependent on another module domain / use internal parts of that modulePS: now im also with te idea of making mediator classses internal - theyere implementation details after all …