Skip to content

StackOverflowException when using flowing scoped lifestyle and injecting a decorated interface inside a class registered as a collection #998

@kevenpoulincanam

Description

@kevenpoulincanam

A StackOverflowException is thrown when using flowing scoped lifestyle and registering a decorator that is injected inside a class which is injected as a collection. A bit hard to describe clearly but the steps to reproduce are simple (see below)

Behavior:

  • Version 5.3.3: Works as expected
  • Version 5.4.0 and up to latest (5.4.5): StackOverflowException

To reproduce:

internal class Program
{
	static void Main()
	{
		var container = new Container();
		container.Options.DefaultScopedLifestyle = ScopedLifestyle.Flowing;
		container.Register<IStrategy, Strategy>();
		container.RegisterDecorator<IStrategy, StrategyDecorator>();
		container.Collection.Register<IMyInterface>(typeof(MyImpl));
		container.Verify();

		Console.WriteLine("All good");
		Console.ReadLine();
	}
}

public interface IMyInterface { }
public class MyImpl : IMyInterface
{
	public MyImpl(IStrategy strategy) { }
}

public interface IStrategy { }
public class Strategy : IStrategy { }
public class StrategyDecorator : IStrategy
{
	public StrategyDecorator(IStrategy strategy) { }
}

Additional context:

  • .Net Framework 4.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions