I have a Class called MyMailSender that binds to the asp.net controller called EmailController.
E.g.
public EmailController(IMailSender sender)
{
//MyMailSender
this.sender = sender;
}
This MyMailSender
class also is dependant on a class called MessageSender
.
Right now my process works without the injection by doing the following.
public class MyMailSender : IMailSender
{
private IMessageSender messageSender;
public MyMailSender()
{
messageSender = new SmtpMessageSender("mail.address.com", 25);
}
}
How can I get this dependant class to bind to the MyMailSender
class using Ninject?
MyMailSender
initial binding is done via controller factory binding
public override void Load()
{
Bind<IMailSender>()
.To<MyMailSender>();
}
I tried binding to the controller factory like:
Bind<IMessageSender>()
.To<SmtpMessageSender>().WithConstructorArgument("mail.address.com", 25);
but I suspect that I should not bind here for this type of binding. What are my options?
My error message is:
Error activating string
No matching bindings are available, and the type is not self-bindable.
Activation path:
4) Injection of dependency string into parameter hostname of constructor of type SmtpMessageSender
3) Injection of dependency IMessageSender into parameter messageSender of constructor of type MyMailSender
2) Injection of dependency IMailSender into parameter sender of constructor of type EmailController
1) Request for EmailController
Suggestions:
1) Ensure that you have defined a binding for string.
2) If the binding was defined in a module, ensure that the module has been loaded into the kernel.
3) Ensure you have not accidentally created more than one kernel.
4) If you are using constructor arguments, ensure that the parameter name matches the constructors parameter name.
5) If you are using automatic module loading, ensure the search path and filters are correct.