c# - Find class that implements generic interface with Ninject -
with ninject can register binding this:
bind(typeof(iqueryhandler<,>)).to(typeof(queryhandler<,>)); but in case don't know name of actual class. know implements interface.
so example, suppose have following:
public class createpagequeryhandler : iqueryhandler<createpage, string> { public string retrieve(createpage query) { ... } } there 1 class implements interface these gerenic params: iqueryhandler<createpage, string>
is there way ninject dynamically instance of class? like:
kernel.get<iqueryhandler<createpage, string>>(); // returns instance of: createpagequeryhandler please note:
i don't want manually bind in registerservices method. i'm looking dynamic way instance of class.
ninject contains batch-registration api. can use following binding instance:
kernel.bind( x => x.fromassembliesmatching("fully.qualified.assemblyname*") .selectallclasses() .inheritedfrom(typeof(iqueryhandler<,>)) .bindbase() );
Comments
Post a Comment