From 248188f4e8f00c502641efb9c92e8bf45971d460 Mon Sep 17 00:00:00 2001 From: Sergei Rogovtcev Date: Sun, 8 Jan 2023 15:54:48 -0500 Subject: [PATCH] autofac/autofac#1361: (FAILING) tests for circular dependencies with PropertiesAutowired when decorator present --- .../Features/CircularDependencyTests.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) 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; } + } }