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

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -