With Ninject you can register a binding like this:
Bind(typeof(IQueryHandler<,>)).To(typeof(QueryHandler<,>));
But in my case I don't know the name of the actual class. All i know is that it implements a certain interface.
So for example, suppose I have the following:
public class CreatePageQueryHandler : IQueryHandler<CreatePage, string>
{
public string Retrieve(CreatePage query)
{ ... }
}
There will be only one class that implements the interface with these gerenic params: IQueryHandler<CreatePage, string>
Is there a way with Ninject to dynamically get an instance of the class? Something like:
kernel.Get<IQueryHandler<CreatePage, string>>(); // returns instance of: CreatePageQueryHandler
Please note:
I don't want to manually bind
this in the RegisterServices
method. I'm looking for a dynamic way to get the instance of the class.