Commit 3b6fd22 1 parent 8f92ac2 commit 3b6fd22 Copy full SHA for 3b6fd22
File tree 2 files changed +39
-0
lines changed
Autofac.Specification.Test/Features
Autofac.Test/Features/Decorators
2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -281,6 +281,26 @@ public void DecoratorAppliedOnlyOnceToComponentWithExternalRegistrySource()
281
281
Assert . IsType < ImplementorA > ( service . Decorated ) ;
282
282
}
283
283
284
+ [ Fact ]
285
+ public void DecoratorCanBeAppliedTwiceIntentionallyWithExternalRegistrySource ( )
286
+ {
287
+ // #965: A nested lifetime scope that has a registration lambda
288
+ // causes the decorator to be applied twice - once for the container
289
+ // level, and once for the scope level.
290
+ var builder = new ContainerBuilder ( ) ;
291
+ builder . RegisterType < ImplementorA > ( ) . As < IDecoratedService > ( ) ;
292
+ builder . RegisterDecorator < DecoratorA , IDecoratedService > ( ) ;
293
+ builder . RegisterDecorator < DecoratorA , IDecoratedService > ( ) ;
294
+ var container = builder . Build ( ) ;
295
+
296
+ var scope = container . BeginLifetimeScope ( b => { } ) ;
297
+ var service = scope . Resolve < IDecoratedService > ( ) ;
298
+
299
+ Assert . IsType < DecoratorA > ( service ) ;
300
+ Assert . IsType < DecoratorA > ( service . Decorated ) ;
301
+ Assert . IsType < ImplementorA > ( service . Decorated . Decorated ) ;
302
+ }
303
+
284
304
[ Fact ]
285
305
public void DecoratorCanBeAppliedTwice ( )
286
306
{
Original file line number Diff line number Diff line change @@ -550,6 +550,25 @@ public void DecoratorAppliedOnlyOnceToComponentWithExternalRegistrySource()
550
550
Assert . IsType < ImplementorA < int > > ( service . Decorated ) ;
551
551
}
552
552
553
+ [ Fact ]
554
+ public void DecoratorCanBeAppliedTwiceIntentionallyWithExternalRegistrySource ( )
555
+ {
556
+ // #965: A nested lifetime scope that has a registration lambda
557
+ // causes the decorator to be applied twice - once for the container
558
+ // level, and once for the scope level.
559
+ var builder = new ContainerBuilder ( ) ;
560
+ builder . RegisterGeneric ( typeof ( ImplementorA < > ) ) . As ( typeof ( IDecoratedService < > ) ) ;
561
+ builder . RegisterGenericDecorator ( typeof ( DecoratorA < > ) , typeof ( IDecoratedService < > ) ) ;
562
+ builder . RegisterGenericDecorator ( typeof ( DecoratorA < > ) , typeof ( IDecoratedService < > ) ) ;
563
+ var container = builder . Build ( ) ;
564
+
565
+ var scope = container . BeginLifetimeScope ( b => { } ) ;
566
+ var service = scope . Resolve < IDecoratedService < int > > ( ) ;
567
+ Assert . IsType < DecoratorA < int > > ( service ) ;
568
+ Assert . IsType < DecoratorA < int > > ( service . Decorated ) ;
569
+ Assert . IsType < ImplementorA < int > > ( service . Decorated . Decorated ) ;
570
+ }
571
+
553
572
[ Fact ]
554
573
public void DecoratorCanBeAppliedTwice ( )
555
574
{
You can’t perform that action at this time.
0 commit comments