This project is read-only.

late binding question

Nov 24, 2014 at 10:20 PM
I have a SendEmail command that has a poco email class and an enum that allows the calling app to chose how to send the email: ie, smtp, rabbitmq, etc.

The service that handles the command passes the enum to a EmailSenderFactory which will return the correct email sender. For the email senders, I have an interface IEmailSender with a Send method, and I have a SmtpEmailSender and a MessageQueueEmailSender. The MessageQueueEmailSender takes a IServiceBus (from Masstransit) and will configure the service bus for either rabbitmq or msmq. The command handler will then just call the send method on the email sender that is returned from the factory.

My issue is that I will have to couple my factory to simple injector in order to create instances of my email senders , which also have ctor dependencies. my composition root is in a different assembly than my email sender factory, command handlers, etc.

How do I do this without passing the container to another assembly?
Nov 25, 2014 at 6:27 AM
That's sinple. The factory implementation should be part of your composition root, while the factory interface should be defined in the application layer itself.
Nov 25, 2014 at 3:55 PM
Ok. So does each assembly need its own composition root?
Nov 25, 2014 at 3:57 PM
Look at the definition of the Composition Root. You typically have one composition root per application, not per assembly.