I'd like to declare a chain of responsibility using decorators in Ninject.
Has anyone done that before?
Thanks.
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.