From 791d9bcc3711cf9d8e893198226215b51373678b Mon Sep 17 00:00:00 2001 From: Travis Illig Date: Sat, 9 Mar 2019 11:16:21 -0800 Subject: [PATCH] Clarified multi-service decoration tests in light of #963. --- test/Autofac.Test/Features/Decorators/DecoratorTests.cs | 5 ++++- .../Features/Decorators/OpenGenericDecoratorTests.cs | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/Autofac.Test/Features/Decorators/DecoratorTests.cs b/test/Autofac.Test/Features/Decorators/DecoratorTests.cs index 81fd4f4b2..be8b2046e 100644 --- a/test/Autofac.Test/Features/Decorators/DecoratorTests.cs +++ b/test/Autofac.Test/Features/Decorators/DecoratorTests.cs @@ -193,7 +193,10 @@ public void DecoratedRegistrationCanIncludeImplementationType() public void DecoratedRegistrationCanIncludeOtherServices() { var builder = new ContainerBuilder(); - builder.RegisterType().As().As(); + + // #963: The SingleInstance here is important - a single component may expose multiple services. + // If that component is decorated, the decorator ALSO needs to expose all of those services. + builder.RegisterType().As().As().SingleInstance(); builder.RegisterDecorator(); var container = builder.Build(); diff --git a/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs b/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs index bca06a1d1..78daf7a02 100644 --- a/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs +++ b/test/Autofac.Test/Features/Decorators/OpenGenericDecoratorTests.cs @@ -190,7 +190,10 @@ public void DecoratedRegistrationCanIncludeImplementationType() public void DecoratedRegistrationCanIncludeOtherServices() { var builder = new ContainerBuilder(); - builder.RegisterGeneric(typeof(ImplementorA<>)).As(typeof(IDecoratedService<>)).As(typeof(IService<>)); + + // #963: The SingleInstance here is important - a single component may expose multiple services. + // If that component is decorated, the decorator ALSO needs to expose all of those services. + builder.RegisterGeneric(typeof(ImplementorA<>)).As(typeof(IDecoratedService<>)).As(typeof(IService<>)).SingleInstance(); builder.RegisterGenericDecorator(typeof(DecoratorA<>), typeof(IDecoratedService<>)); var container = builder.Build();