Bug: Registrations are wrong for .NET Core version.
Opened this issue · 0 comments
hypercodeplace commented
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.