I have a factory method called MessageHandlerFactory
public class MessageHandlerFactory : IMessageHandlerFactory<IMessage>
{
public IMessageHandler<IMessage> GetMessageHandler()
{
return new MessageHandler_1();
}
}
... and the following message Handler
public class MessageHandler_1 : IMessageHandler<Message>
{
//Do Something…
}
public class Message : IMessage
{
public String Name {get; set;}
}
MessageHandlerFactory needs to be assigned to all occurrences of IMessageHandlerFactory in my project so that calls to IMessageHandlerFactory.GetMessageHandler() will return an instance of MessageHandler_1. (In my actual code, I have multiple implementations of IMessageHandler and IMessageHandlerFactory.GetMessageHandler would return an appropriate implementation based on some conditions...). Here is how I do my Ninject binding
Bind<IMessageHandlerFactory<IMessage>>().To<MessageHandlerFactory>();
Bind<IMessageHandler<Message>>().To<MessageHandler_1>();
But when I try accessing the MessageHandlerFactory.GetMessageHandler, I get the following exception
Ninject.ActivationException: Error activating IMessageHandler{IMessage} No matching bindings are available, and the type is not self-bindable. Activation path: 1) Request for IMessageHandler{IMessage}
Wondering how I could fix it? I have been playing with this for quite sometime without any success. Any help would be greatly appreciated!!