naming conventions - Why can't I use Get<ClassNameOfConcreteInstance> as a method name in Ninject Extension Factory? -


look @ simple example: calling createcar works, calling getcar fails, saying "error activating icar: no matching bindings available, , type not self-bindable".

  public interface icar { }    public class car : icar   {     public car(string cartype) { }   }    public interface icarfactory   {     icar createcar(string cartype); // fine     icar getcar(string cartype);    // bad   }    public class carmodule : ninjectmodule   {     public override void load()     {       bind<icarfactory>().tofactory();       bind<icar>().to<car>();     }   }    public class program   {     public static void main()     {       using (var kernel = new standardkernel(new funcmodule(), new carmodule()))       {         var factory = kernel.get<icarfactory>();         var car1 = factory.createcar("a type");         var car2 = factory.getcar("another type");       }     }   } 

is assume must related kind of convention get*classname* (something namedlikefactorymethod stuff). there way avoid convention applied? don't need , don't want (i wasted time trying figure out why binding failing, luck made typo in 1 of 10 factories , noticed work because factory method name "ger" instead of "get").

thanks!

yes, there convention, get used obtain instances using named binding. factory extension generates code don't have create boilerplate code factories. don't need use it, if don't want to.

but if do, bound conventions. use create build instances , get retrieve instances via named binding.

all documented in wiki.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -