@@ -276,10 +276,47 @@ public void DecoratorAppliedOnlyOnceToComponentWithExternalRegistrySource()
276
276
277
277
var scope = container . BeginLifetimeScope ( b => { } ) ;
278
278
var service = scope . Resolve < IDecoratedService > ( ) ;
279
+
279
280
Assert . IsType < DecoratorA > ( service ) ;
280
281
Assert . IsType < ImplementorA > ( service . Decorated ) ;
281
282
}
282
283
284
+ [ Fact ]
285
+ public void DecoratorCanBeAppliedTwice ( )
286
+ {
287
+ var builder = new ContainerBuilder ( ) ;
288
+ builder . RegisterType < ImplementorA > ( ) . As < IDecoratedService > ( ) ;
289
+ builder . RegisterDecorator < DecoratorA , IDecoratedService > ( ) ;
290
+ builder . RegisterDecorator < DecoratorA , IDecoratedService > ( ) ;
291
+ var container = builder . Build ( ) ;
292
+
293
+ var service = container . Resolve < IDecoratedService > ( ) ;
294
+
295
+ Assert . IsType < DecoratorA > ( service ) ;
296
+ Assert . IsType < DecoratorA > ( service . Decorated ) ;
297
+ Assert . IsType < ImplementorA > ( service . Decorated . Decorated ) ;
298
+ }
299
+
300
+ [ Fact ]
301
+ public void DecoratorCanBeAppliedTwiceInChildLifetimeScope ( )
302
+ {
303
+ var builder = new ContainerBuilder ( ) ;
304
+ builder . RegisterType < ImplementorA > ( ) . As < IDecoratedService > ( ) ;
305
+ builder . RegisterDecorator < DecoratorA , IDecoratedService > ( ) ;
306
+ var container = builder . Build ( ) ;
307
+
308
+ var scope = container . BeginLifetimeScope ( b => b . RegisterDecorator < DecoratorA , IDecoratedService > ( ) ) ;
309
+ var scopeInstance = scope . Resolve < IDecoratedService > ( ) ;
310
+
311
+ Assert . IsType < DecoratorA > ( scopeInstance ) ;
312
+ Assert . IsType < DecoratorA > ( scopeInstance . Decorated ) ;
313
+ Assert . IsType < ImplementorA > ( scopeInstance . Decorated . Decorated ) ;
314
+
315
+ var rootInstance = container . Resolve < IDecoratedService > ( ) ;
316
+ Assert . IsType < DecoratorA > ( rootInstance ) ;
317
+ Assert . IsType < ImplementorA > ( rootInstance . Decorated ) ;
318
+ }
319
+
283
320
[ Fact ]
284
321
public void DecoratorCanBeAppliedToServiceRegisteredInChildLifetimeScope ( )
285
322
{
0 commit comments