Skip to content

StackOverflowException with generic composite #465

Open
@WolfgangKluge

Description

@WolfgangKluge

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions