c# 4.0 - Unable to get default constructor for Integration class ninject -


i'm new on using ninject , dependency injection, , have problem using it.

i try using ninject on class libray, , building integration tests. now, see in many example that, using ninject specified di module this:

public class dimodule : ninjectmodule public override void load() {         bind<iusaservices>().to<usaservices>(); }  

and on test class, try call dependency this:

[testclass] public class usaintegrationtests {      private readonly iusaservices _usaservice;      public usaintegrationtests(iusaservices usaservices)     {         _usaservice = usaservices;     }      [testmethod]     public void validateusertests()     {         assert.istrue(_usaservice.validateuser("username1", "password1"));     } } 

and getting error:

unable default constructor class usatests.integrationtests.usaintegrationtests. 

however read documentation , tried this:

[testclass] public class usaintegrationtests {      private readonly iusaservices _usaservice;      public usaintegrationtests()     {         using (ikernel kernel = new standardkernel(new dimodule()))         {             _usaservice = kernel.get<iusaservices>();         }     }      [testmethod]     public void validateusertests()     {         assert.istrue(_usaservice.validateuser("mantab", "banget"));     } } 

the test works properly. question is, why getting error? way around it? in advance.

unit test frameworks require test classes have default constructor. can't integrate di containers them. instead of using constructor injection, have call container directly code, although unit tests should typically not have container @ (for integration tests however, okay).


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -