You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Under Autofac 4.9.4 if you decorate a service that is marked PropertiesAutowired using the new decorator syntax, the property injection fails. Using the original decorator syntax property injection succeeds.
publicinterfaceIService{boolNestedServiceIsNotNull();}publicclassService:IService{publicNestedServiceNestedService{get;set;}publicboolNestedServiceIsNotNull(){returnNestedService!=null;}}publicclassNestedService{}publicclassServiceDecorator:IService{privatereadonlyIService_original;publicServiceDecorator(IServiceoriginal){_original=original;}// The decorator doesn't have the property to inject,// only the service being decorated has it.publicboolNestedServiceIsNotNull(){return _original.NestedServiceIsNotNull();}}publicclassUnitTest1{[Fact]publicvoidPropertyInjectionWithoutDecoratorWorks(){varbuilder=new ContainerBuilder();
builder.RegisterType<NestedService>();
builder.RegisterType<Service>().As<IService>().PropertiesAutowired();varcontainer= builder.Build();varservice= container.Resolve<IService>();
Assert.True(service.NestedServiceIsNotNull());}[Fact]publicvoidPropertyInjectionFailsWithNewDecoratorSyntax(){varbuilder=new ContainerBuilder();
builder.RegisterType<NestedService>();
builder.RegisterType<Service>().As<IService>().PropertiesAutowired();// Decorating the service with the new syntax causes the assertion to fail.
builder.RegisterDecorator<ServiceDecorator,IService>();varcontainer= builder.Build();varservice= container.Resolve<IService>();
Assert.True(service.NestedServiceIsNotNull());}[Fact]publicvoidPropertyInjectionWorksWithOldSyntax(){varbuilder=new ContainerBuilder();
builder.RegisterType<NestedService>();// Decorating the service with the old syntax works.
builder.RegisterType<Service>().Named<IService>("service").PropertiesAutowired();
builder.RegisterDecorator<IService>((c,inner)=>new ServiceDecorator(inner), fromKey:"service");varcontainer= builder.Build();varservice= container.Resolve<IService>();
Assert.True(service.NestedServiceIsNotNull());}}
The text was updated successfully, but these errors were encountered:
Hi @tillig I think the reason is that the instance is decorated before the component raises activating event for its original instance. It happens also if we register with provided instance method. I have created a PR #1043 to fix it, Can you check about it ?
Under Autofac 4.9.4 if you decorate a service that is marked
PropertiesAutowired
using the new decorator syntax, the property injection fails. Using the original decorator syntax property injection succeeds.The text was updated successfully, but these errors were encountered: