diff --git a/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs b/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs index 8216adb6f..74bf2628a 100644 --- a/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs +++ b/test/Autofac.Specification.Test/Features/CircularDependencyTests.cs @@ -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() + .SingleInstance(); + builder.RegisterType() + .As(); + builder.RegisterType() + .SingleInstance() + .PropertiesAutowired(PropertyWiringOptions.AllowCircularDependencies); + + builder.RegisterDecorator(); + + using var container = builder.Build(); + var outer = container.Resolve(); + var innerMost = container.Resolve(); + + Assert.Same(outer, innerMost.Outer); + } + private interface ICircularDependencyA { ICircularDependencyB DependencyB { get; } @@ -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; } + } }