1

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

Federico
  • 3,782
  • 32
  • 46

1 Answers1

0

The detail is too long for the comment, so I had to put it in another section

When I use watch I see this: Value cannot be null.Parameter name: source

stackTrace is:

 at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at ThePoint.Ingestion.Abstract.FeedsProcessor..ctor() in c:\Users\houyang\Documents\GitHub\The-Point-Redesign\ThePoint.Ingestion\Abstract\FeedsProcessor.cs:line 34
   at ThePoint.Ingestion.Abstract.WebServiceFeedsProcessor..ctor()
   at ThePoint.Ingestion.Concrete.GannettLocalProcessorTest..ctor()
   at DynamicInjector08125ba6b65f454d9309fa177f39cd2d(Object[] )
   at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 97
   at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157
   at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at Ninject.ResolutionExtensions.Get[T](IResolutionRoot root, IParameter[] parameters) in c:\Projects\Ninject\ninject\src\Ninject\Syntax\ResolutionExtensions.cs:line 37