LightInject
LightInject copied to clipboard
StackOverflowException with generic composite
Hi,
when I try to get the composite pattern to work with generics, I get a StackOverflowException..
void CompositeTest() {
using (var container = new ServiceContainer()) {
container.Register<FooA>();
container.Register<FooB>();
container.Register<FooC>();
container.Register(typeof(IFoo<>), typeof(Composite<>));
container.Register<IFoo<string>, StringComposite>();
container.Register<StringComposite>();
container.GetAllInstances<StringComposite>(); // StackOverflow-Exception
container.GetAllInstances<IFoo<string>>(); // StackOverflow-Exception
container.GetAllInstances<IFoo<int>>(); // StackOverflow-Exception
}
}
interface IFoo { }
interface IFoo<T> : IFoo { }
class FooA : IFoo<string> { }
class FooB : IFoo<string>, IFoo<int> { }
class FooC : IFoo<int> { }
class Composite<T> : IFoo<T> {
public Composite(IEnumerable<IFoo<T>> fooList) { }
}
class StringComposite : Composite<string> {
public StringComposite(IEnumerable<IFoo<string>> fooList) : base(fooList) { }
}
- Version: 5.3.0
- Platform: WIndows 10 / .net 4.7.3221.0
What do I miss here?
Ups, I think that's from my tests..
The same error occurs, if I use one of these...
container.GetInstance<StringComposite>();
container.GetInstance<IFoo<string>>();
container.GetInstance<IFoo<int>>();
Thanks for reporting this. Will look into it
I ran into the same issue, it still presents in 6.3.3. Do you have an understanding on how it could be fixed?