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

Bug: Registrations are wrong for version 5.9.0 and later #160

Closed
hypercodeplace opened this issue Apr 25, 2019 · 0 comments
Closed

Bug: Registrations are wrong for version 5.9.0 and later #160

hypercodeplace opened this issue Apr 25, 2019 · 0 comments
Assignees
Labels
release Release branch

Comments

@hypercodeplace
Copy link

Description

It's not the same as unitycontainer/interception#30, but perhaps it is related to each other. The following test is failed both for .NET Core and Framework. Look at the comments in the code to more information.

To Reproduce

[Test]
public void UnityTest()
{
    for (var i = 0; i < 10000; i++) {
        var container = new UnityContainer()
            .RegisterType<IFoo, Foo>()
            .RegisterType<IBar, Bar>()
            // It's important the name is random
            .RegisterType<IBar, Bar>(Guid.NewGuid().ToString());

        var child = container
            .CreateChildContainer()
            .RegisterType<IFoo, Foo>(new ContainerControlledLifetimeManager());

        var registrations = child.Registrations
            .Where(r => r.RegisteredType == typeof(IFoo))
            .ToList();

        Assert.IsNotNull(
            registrations.FirstOrDefault(r => r.LifetimeManager is ContainerControlledLifetimeManager),
            "Singleton registration not found on iteration #" + i);

        // This check fails on random iteration, usually i < 300.
        // It passes for v.5.8.13 but fails for v.5.9.0 and later both for .NET Core and for Framework.
        Assert.IsNull(
            registrations.FirstOrDefault(r => r.LifetimeManager is TransientLifetimeManager),
            "Transient registration found on iteration #" + i);
    }
}

public interface IFoo { }
public class Foo : IFoo { }

public interface IBar { }
public class Bar : IBar { }

Expected behavior

There must be no transient registration in the child container, but it is on random iteration.

@ENikS ENikS self-assigned this Apr 25, 2019
@ENikS ENikS added the bug label Apr 25, 2019
@ENikS ENikS added this to the 5.11.0 milestone Apr 25, 2019
commit-n-run added a commit to commit-n-run/container that referenced this issue Jun 7, 2019
`Entry.Next` should contain index+1 as assumed by the loop above.

This fixes invalid registration behavior as noted by (this issue)[unitycontainer#160]
ENikS added a commit that referenced this issue Nov 14, 2020
Fixed #140
Fixed #160
@github-actions github-actions bot added the release Release branch label Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release Release branch
Projects
None yet
Development

No branches or pull requests

2 participants