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
In the following example, the factory tries to construct an instance of Class2 passing the argument "argumentA" of type IClass1 passed to the factory method to Class2's constructor instead of using the binding rule to create an instance of Class3. This throws an invalid cast exception.
If I change the name of the constructor argument of Class2 to "ArgumentB" the code works.
Ninject.Extension.Factory v3.3.2
Ninject v3.3.4
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Ninject;using Ninject.Extensions.Factory;namespaceConsoleApp19{classProgram{staticvoidMain(string[]args){varkernel=new StandardKernel();
kernel.Bind<IClass1>().To<Class1>();
kernel.Bind<IClass2>().To<Class2>();
kernel.Bind<IClass3>().To<Class3>();
kernel.Bind<IClass4>().To<Class4>();
kernel.Bind<IClass4Factory>().ToFactory();varfactory= kernel.Get<IClass4Factory>();varclass1= kernel.Get<IClass1>();// fails with exception Unable to cast object of type 'ConsoleApp19.Class1' to type 'ConsoleApp19.IClass3'varclass4= factory.CreateInstance(class1);}}publicinterfaceIClass1{}publicclassClass1:IClass1{}publicinterfaceIClass2{}publicclassClass2:IClass2{publicClass2(IClass3argumentA){}}publicinterfaceIClass3{}publicclassClass3:IClass3{}publicinterfaceIClass4{}publicinterfaceIClass4Factory{
IClass4 CreateInstance(IClass1argumentA);}publicclassClass4:IClass4{publicClass4(IClass1argumentA,IClass2class2){}}}
The text was updated successfully, but these errors were encountered:
In the following example, the factory tries to construct an instance of Class2 passing the argument "argumentA" of type IClass1 passed to the factory method to Class2's constructor instead of using the binding rule to create an instance of Class3. This throws an invalid cast exception.
If I change the name of the constructor argument of Class2 to "ArgumentB" the code works.
Ninject.Extension.Factory v3.3.2
Ninject v3.3.4
The text was updated successfully, but these errors were encountered: