Skip to content

Commit

Permalink
autofac#1361: (FAILING) tests for circular dependencies with Properti…
Browse files Browse the repository at this point in the history
…esAutowired when decorator present
  • Loading branch information
srogovtsev committed Jan 8, 2023
1 parent 90284ef commit 248188f
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,29 @@ public void CircularDependenciesHandledWhenAllDependenciesPropertyInjected()
Assert.Same(host.DependencyB, host.DependencyA.DependencyB);
}

[Fact]
public void CircularDependenciesHandledWhenDecoratorInDependencyChain()
{
// Issue #1361 - Decorator in dependency chain breaks circular dependency resolution
var builder = new ContainerBuilder();

builder.RegisterType<OuterService>()
.SingleInstance();
builder.RegisterType<InnerService>()
.As<IInnerService>();
builder.RegisterType<InnermostService>()
.SingleInstance()
.PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies);

builder.RegisterDecorator<InnerServiceDecorator, IInnerService>();

using var container = builder.Build();
var outer = container.Resolve<OuterService>();
var innerMost = container.Resolve<InnermostService>();

Assert.Same(outer, innerMost.Outer);
}

private interface ICircularDependencyA
{
ICircularDependencyB DependencyB { get; }
Expand Down Expand Up @@ -341,4 +364,35 @@ public ServiceImpl(Guid id)
{
}
}

// Issue #1361 - Decorator in dependency chain breaks circular dependency resolution
private class OuterService
{
public OuterService(IInnerService service)
{
}
}

private interface IInnerService
{
}

private class InnerService : IInnerService
{
public InnerService(InnermostService service)
{
}
}

private class InnerServiceDecorator : IInnerService
{
public InnerServiceDecorator(IInnerService toDecorate)
{
}
}

private class InnermostService
{
public OuterService Outer { get; set; }
}
}

0 comments on commit 248188f

Please sign in to comment.