diff --git a/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs b/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs index 9c2caa0c2..ccb44bff6 100644 --- a/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs +++ b/test/Autofac.Specification.Test/Lifetime/LifetimeEventTests.cs @@ -593,17 +593,31 @@ public void OnReleaseForSingletonAsInterfaceStillFiresIfNotResolved() Assert.True(instance.Released); } - [Fact] - public void ActivatedAllowsBypassingCircularDependencies() + private static readonly Action[] ConfigurationsForCircularDependenciesImpl = + { + builder => { }, + builder => builder.RegisterDecorator(), + builder => builder.RegisterDecorator((_, __, toDecorate) => new InnerServiceDecorator(toDecorate)), + }; + + public static readonly object[][] ConfigurationsForCircularDependencies = + ConfigurationsForCircularDependenciesImpl.Select(c => new object[] {c}).ToArray(); + + [Theory] + [MemberData(nameof(ConfigurationsForCircularDependencies))] + public void ActivatedAllowsBypassingCircularDependencies(Action additionalContainerConfiguration) { var builder = new ContainerBuilder(); builder.RegisterType() - .SingleInstance(); - builder.RegisterType(); + .SingleInstance(); + builder.RegisterType() + .As(); builder.RegisterType() - .SingleInstance() - .OnActivated(args => args.Instance.Outer = args.Context.Resolve()); + .SingleInstance() + .OnActivated(args => args.Instance.Outer = args.Context.Resolve()); + + additionalContainerConfiguration(builder); using var container = builder.Build(); var outer = container.Resolve(); @@ -654,18 +668,29 @@ public void Method(int param) private class OuterService { - public OuterService(InnerService service) + public OuterService(IInnerService service) { } } - private class InnerService + 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; }