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 .NET Core version. #30

Open
hypercodeplace opened this issue Apr 23, 2019 · 0 comments
Open

Bug: Registrations are wrong for .NET Core version. #30

hypercodeplace opened this issue Apr 23, 2019 · 0 comments

Comments

@hypercodeplace
Copy link

hypercodeplace commented Apr 23, 2019

Description

It's not the same as unitycontainer/container#160, but perhaps it is related to each other.

How to reproduce

Compile and run the following code for .NET Core (I tried for 2.1) and Framework (tried for 4.7.2). The output is different.

class Program
{
    static void Main(string[] args)
    {
        var container = new UnityContainer()
            .AddNewExtension<Interception>()
            .RegisterType<Foo>()
            .RegisterType<IBar, Bar>();

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

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

        foreach (var registration in registrations)
        {
            Console.WriteLine(
                $"{registration.RegisteredType.Name}->" +
                $"{registration.MappedToType.Name}" +
                $"[{registration.LifetimeManager}]");
        }
    }

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

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

For Framework version the output is

Foo->Foo[Lifetime:PerContainer]

But for .NET Core version is:

Foo->Foo[Lifetime:Transient]
Foo->Foo[Lifetime:PerContainer]

Expected behavior

For .NET Core must be the same registration as for Framework. The transient registration is obviously wrong.

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