Skip to content

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

Closed

Description

@hypercodeplace

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.

Activity

  1. self-assigned this
    on Apr 25, 2019
  2. added this to the milestone on Apr 25, 2019
  3. added a commit that references this issue on Nov 14, 2020
    46ef29d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

releaseRelease branch

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions