I'd like to use LightInject's constructor injection feature, but I'd like to clear up things first about lifetime management of IDisposables.
Consider the following:
Example A
public class Foo : IDisposable
{
readonly IBar bar;
public Foo(IBar bar)
{
this.bar = bar;
}
public void Dispose()
{
}
}
Example B
public class Foo : IDisposable
{
readonly IBar bar;
public Foo(Func<string, IBar> bar)
{
this.bar = bar("myParameter");
}
public void Dispose()
{
}
}
My questions for both examples:
- Will Dispose method be called by LightInject on IBar after Foo is disposed or should I call dispose myself?
- If IBar is using a PerContainerLifeTime, will Dispose be called after every Foo instance disposed?
Edit Well the 2nd question is stupid I realize, a PerContainerLifeTime instance is of course disposed when the container is Disposed. My overall question would be, is LightInject tracking injected dependencies, and dispose them itself?