I have two branches under my master interface, and try to use Ninject IOC here to dynamically load proper class based on some condiction. here is my description of my class structure and problem I have
Interface I
{
Void method1 ();
Void method2 ();
Void method3 ();
}
Abstract class A : I
{
Abstract void method1 ();
Abstract void method2 ();
Void Method3() { //Some implementation can be shared by all classes }
}
Branch 1
Abstract Class B : A
{
void method1 () { //Some implementation can be shared by B1, B2 }
}
B1 and B2 are lowest level classes in branch1, which will be used in the code
Class B1 : B
{
Void Method2() { //Some implementation }
}
Class B2 : B
{
Void Method2() { //Some implementation }
}
But there is another branch start from inhabitant from Abstract class A, as following
Branch 2
Abstract Class C : A
{
void method1 ()
{
//Some implementation which is different from in B.Method1
//and can be shared by C1
}
}
C1 are lowest level classes in branch2, which will be used in the code
Class C1 : C
{
Void Method2() { //Some implementation }
}
I use Ninject to bind and get to load classes dynamically, like below:
Bind<I>().To<B1>();
Bind<I>().To<B2>();
Bind<I>().To<C1>();
And retrieve them like using kernel.Get<I>();
Now the issue is that B1 and B2 are retuned ok, but when I retrieve C1, it always throw an null error. Am I missing something here? Any help is appreciated