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
If there is a class that implements multiple interfaces and you want to decorate one of them, resolution of the other interfaces ends up with an InvalidCastException. If there are decorators for all implemented interfaces, resolution of any interface ends up in StackOverflowException.
See the code to reproduce the issue (using Autofac 4.9.4 and .Net Framework 4.8):
usingSystem;namespaceAutofac{interfaceI1{voidMethod1();}interfaceI2{voidMethod2();}classC:I1,I2{publicvoidMethod1(){Console.WriteLine("C.Method1");}publicvoidMethod2(){Console.WriteLine("C.Method2");}}classD1:I1{privatereadonlyI1_inner;publicD1(I1inner){_inner=inner;}publicvoidMethod1(){Console.WriteLine("D1.Method1");_inner.Method1();}}classD2:I2{privatereadonlyI2_inner;publicD2(I2inner){_inner=inner;}publicvoidMethod2(){Console.WriteLine("D2.Method2");_inner.Method2();}}classProgram{staticvoidMain(string[]args){varbuilder=newContainerBuilder();builder.RegisterType<C>().AsImplementedInterfaces();builder.RegisterDecorator<D1,I1>();//builder.RegisterDecorator<D2, I2>(); if out-commented, container.Resolve<I1>() ends up in StackOverflowExceptionvarcontainer=builder.Build();container.Resolve<I1>().Method1();container.Resolve<I2>().Method2();// ends up in InvalidCastException}}}
The text was updated successfully, but these errors were encountered:
If there is a class that implements multiple interfaces and you want to decorate one of them, resolution of the other interfaces ends up with an InvalidCastException. If there are decorators for all implemented interfaces, resolution of any interface ends up in StackOverflowException.
See the code to reproduce the issue (using Autofac 4.9.4 and .Net Framework 4.8):
The text was updated successfully, but these errors were encountered: