Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When Resolve is called multiple times, the parent collection is bound to the child container. #333

Closed
adarapata opened this issue Jan 14, 2022 · 1 comment

Comments

@adarapata
Copy link
Collaborator

adarapata commented Jan 14, 2022

Hi 😄
I'm reporting what may be a glitch.

varsion: 1.10.0

Example

        [Test]
        public void ResolveCollectionFromParentByContinuous()
        {
            var builder = new ContainerBuilder();
            builder.Register<I1, MultipleInterfaceServiceA>(Lifetime.Singleton);
            builder.Register<I1, MultipleInterfaceServiceB>(Lifetime.Singleton);
            var parentContainer = builder.Build();

            var childContainer = parentContainer.CreateScope(childBuilder =>
            {
                childBuilder.Register<I1, MultipleInterfaceServiceC>(Lifetime.Singleton);
                childBuilder.Register<I1, MultipleInterfaceServiceD>(Lifetime.Singleton);
            });
            
            var scopedService = childContainer.Resolve<IReadOnlyList<I1>>();
            var moreScopedService = childContainer.Resolve<IReadOnlyList<I1>>();
            Assert.That(moreScopedService.Count(), Is.EqualTo(4));
        }

result

VContainer.VContainerException : Conflict implementation type : Registration MultipleInterfaceServiceA ContractTypes=[VContainer.Tests.I1] Singleton VContainer.Internal.InstanceProvider

If you check the contents of CollectionRegistration when you call Resolve for the second time, you will see that even the objects of the parent container are registered

registration = {Registration} Registration I1[] ContractTypes=[System.Collections.Generic.IEnumerable`1[VContainer.Tests.I1], System.Collections.Generic.IReadOnlyList`1[VContainer.Tests.I1]] Transient CollectionRegistration VContainer.Tests.I1[] ContractTypes=[System.Collections.Gener…
 ImplementationType = {RuntimeType} VContainer.Tests.I1[]
 InterfaceTypes = {List<Type>} Count = 2
 Lifetime = {Lifetime} Transient
 Provider = {CollectionInstanceProvider} CollectionRegistration VContainer.Tests.I1[] ContractTypes=[System.Collections.Generic.IEnumerable`1[VContainer.Tests.I1], System.Collections.Generic.IReadOnlyList`1[VContainer.Tests.I1]] Transient
   [0] = {Registration} Registration MultipleInterfaceServiceC ContractTypes=[VContainer.Tests.I1] Singleton VContainer.Internal.InstanceProvider
   [1] = {Registration} Registration MultipleInterfaceServiceD ContractTypes=[VContainer.Tests.I1] Singleton VContainer.Internal.InstanceProvider
   [2] = {Registration} Registration MultipleInterfaceServiceA ContractTypes=[VContainer.Tests.I1] Singleton VContainer.Internal.InstanceProvider
   [3] = {Registration} Registration MultipleInterfaceServiceB ContractTypes=[VContainer.Tests.I1] Singleton VContainer.Internal.InstanceProvider

Is it likely that calling Merge will keep it from being added?
https://github.com/hadashiA/VContainer/pull/321/files#diff-aac4b91a82b34e6b999dd0cfb9d5e8cc2844cee54550c909d0018ee452fdd387R162

@adarapata
Copy link
Collaborator Author

It's resolved by

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant