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
static void Main(string[] args)
{
var container = new ServiceContainer();
container.Register<Dep1>(new PerContainerLifetime());
// If I use container.Register<Dep2>(new PerContainerLifetime()); dispose order is as expected.
container.Register(factory => new Dep2(factory.GetInstance<Dep1>()), new PerContainerLifetime());
container.Register<Dep3>(new PerContainerLifetime());
container.GetInstance<Dep3>();
container.Dispose();
Console.ReadKey();
}
public class Dep1 : IDisposable
{
private bool _disposed;
public void Dispose()
{
Console.WriteLine("Dispose 1");
_disposed = true;
}
public void DoSomething()
{
if (_disposed)
Console.WriteLine("Fail");
}
}
public class Dep2
{
private readonly Dep1 _dep;
public Dep2(Dep1 dep)
{
_dep = dep;
}
public void DoSomething()
{
_dep.DoSomething();
}
}
public class Dep3 : IDisposable
{
private readonly Dep2 _dep;
public Dep3(Dep2 dep)
{
_dep = dep;
}
public void Dispose()
{
Console.WriteLine("Dispose 3");
_dep.DoSomething();
}
}
I expected dispose order be like this: Dep3.Dispose(), Dep1.Dispose().
But it actualy is Dep1.Dispose(), Dep3.Dispose()
The text was updated successfully, but these errors were encountered:
I am trying to do something like this:
I expected dispose order be like this: Dep3.Dispose(), Dep1.Dispose().
But it actualy is Dep1.Dispose(), Dep3.Dispose()
The text was updated successfully, but these errors were encountered: