4

I'd like to declare a chain of responsibility using decorators in Ninject.

Has anyone done that before?

Thanks.

Elijah
  • 13,368
  • 10
  • 57
  • 89
Adriano Machado
  • 223
  • 3
  • 16
  • 1
    I would just like to point out that chain of responsibility and decorators are different design patterns entirely, perhaps that is why you're having trouble getting answers to this question? – George Mauer Apr 14 '09 at 14:39

2 Answers2

13

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

Sean Chambers
  • 8,572
  • 7
  • 41
  • 55
2

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.

chrisb
  • 2,200
  • 1
  • 20
  • 23