I'd like to declare a chain of responsibility using decorators in Ninject.
Has anyone done that before?
Thanks.
In the new ninject 2.0 syntax you can accomplish this by the following newer syntax:
Bind<IEmailSender>().To<LoggingEmailSender>();
Bind<IEmailSender>().To<SmtpClientEmailSender>().WhenInjectedInto<LoggingEmailSender>();
Just ran into this myself and found that was the way to do it as ForMembersOf has been removed in ninject 2.0
Assuming I'm understanding the question properly, one approach is something like this:
Bind<IEmailSender>().To<LoggingEmailSender>();
Bind<IEmailSender>().To<SmtpClientEmailSender>().ForMembersOf<LoggingEmailSender>();
The LoggingEmailSender class would have a constructor something like:
LoggingEmailSending(IEmailSender sender)
This should get you a decorator easily enough - just remember that without using attributes, you're kinda limited to a single constructor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With