DevTeam / Pure.DI

Pure DI for .NET
MIT License
410 stars 21 forks source link

Invalid code with duplicate field names is generated in case if multiple roots are dependent on external argument #38

Closed MaxWellHays closed 5 months ago

MaxWellHays commented 5 months ago

Description

I am using Pure.DI 2.1.1 and I have a registration scheme with multiple roots exposed. I pass IExternalDependency as an argument to the Composition constructor, and multiple types have a dependency on this IExternalDependency. However, this configuration leads to invalid code being generated, and I see the following errors during the compilation phase:

Error CS0100: The parameter name 'externalDependency' is a duplicate
Error CS0102: The type 'Composition' already contains a definition for '_argM02D18di_externalDependency'

Example

DI.Setup("Composition")
    .Bind<IService1>().As(Lifetime.Singleton).To<Service1>()
    .Bind<IService2>().As(Lifetime.Singleton).To<Service2>()
    .Bind<IRootService>().As(Lifetime.Singleton).To<RootService>()
    .Arg<IExternalDependency>("externalDependency")
    .Root<IService1>("Service1")
    .Root<IRootService>("Root");

Repository

tests/Pure.DI.UsageTests/Basics/ArgumentsScenario2.cs

NikolayPianikov commented 5 months ago

Thank you for the bug report. This issue has been fixed in 2.1.2