c# - Ninject resolve all for interface type -
public selectuserquery: iquery{ public string command { get{ return "...."; } } } public class querydispatcher : iquerydispatcher { //... //.. public void dispatch<tquery>(tquery query) tquery : iquery { foreach (var handler in kernel.resolveall<iqueryhandler<tquery>>()) { handler.handle(query); } } } public class querymanager{ //... public activate(){ querydispatcher.dispatch(new selectuserquery()); } }
this resolving types used querydispatcher.dispatch(new selectuserquery());
but creating private method in querymanager run dispatch operations this:
public class querymanager{ //... public seletectuser(){ apply(new selectuserquery()); } private apply(iquery query){ querydispatcher.dispatch(query); } }
this not working. kernel.resolveall<iqueryhandler<tquery>>()
returning empty collection.
bindings this:
public class servicemodule: ninjectmodule { public override void load() { kernel.bind<iqueryhandler<selectuserquery>>().to<selectuserqueryhandler>(); kernel.bind<iquerydispatcher>().to<querydispatcher>(); } }
Comments
Post a Comment