You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have been using Unity version older than 5.2.1 and now started upgrading to newer versions (5.7.0).
Our previous code was working fine because of this issue #35 , but with the upgrade it started breaking.
We followed the suggestion mentioned in the above issue of registering concrete class explicitly. It worked fine when we have one child container, but is not working with second child container.
Below is the code
public class Program
{
public interface IUnitOfWork
{
}
public class Dtrcontext : IUnitOfWork
{
}
public void Main()
{
IUnityContainer container = new UnityContainer();
container.RegisterType<IUnitOfWork, Dtrcontext>(new HierarchicalLifetimeManager());
container.RegisterType<Dtrcontext>(new HierarchicalLifetimeManager());
var child1 = container.CreateChildContainer();
var child2 = container.CreateChildContainer();
var a = container.Resolve<Dtrcontext>();
var b = child1.Resolve<Dtrcontext>();
var c = child1.Resolve<IUnitOfWork>();
var d = child2.Resolve<Dtrcontext>();
var e = child2.Resolve<IUnitOfWork>();
Console.WriteLine("a=b?" +(a==b ).ToString());
Console.WriteLine(" b=c? " +(b==c ).ToString());
Console.WriteLine(" d=e? " +(d==e ).ToString());
Console.WriteLine(" b=d? " +(b==d ).ToString());
}
}
Result :
a=b?False
b=c? True
d=e? False --> This is expected to be true.
b=d? False
Wanted to know if this is a know issue and is there any solution.
The text was updated successfully, but these errors were encountered:
laxmanrapolu
changed the title
Second child container not resolving type properly
Second child container not resolving type properly with Hierarchical Lifetime
Jan 23, 2020
We have been using Unity version older than 5.2.1 and now started upgrading to newer versions (5.7.0).
Our previous code was working fine because of this issue #35 , but with the upgrade it started breaking.
We followed the suggestion mentioned in the above issue of registering concrete class explicitly. It worked fine when we have one child container, but is not working with second child container.
Below is the code
public class Program
{
}
Result :
a=b?False
b=c? True
d=e? False --> This is expected to be true.
b=d? False
Fiddler link -> https://dotnetfiddle.net/Uka9UQ
Wanted to know if this is a know issue and is there any solution.
The text was updated successfully, but these errors were encountered: