Service code: public EmailNotificationService(IFormatter emailFormatter){...} Dependency registration code: container. Register( Component. ForNamed("TextMessageFormatter"), Component.
ForServiceOverrrides( ServiceOverride. ForKey("emailFormatter"). Eq("EmailFormatter")) ).
Thanks for the answer. I was searching for the wrong things. :D – User Aug 7 at 17:51 Glad I could help.
– Zach Shewmaker Aug 7 at 17:58.
Don't try to solve this problem in the DI configuration. Instead, solve it in the design of the application. It seems to me that you have defined several distinct things with the same interface.
Your requirements makes it pretty obvious, since you say: I want to inject EmailFormatter You don't want to inject a formatter; you want to inject an e-mail formatter. In other words, make this clear in the application. Define an IEmailFormatter interface and let the EmailNotificationService depend on this: public interface IEmailFormatter { string Format(CompletedItem completedItem); } public class EmailNotificationService { public EmailNotificationService(IEmailFormatter formatter) { } } This has two important advantages: It makes the code more maintainable, since now it is clear what kind of dependency EmailNotificationService really URL1 makes the DI configuration much easier and more maintainable.
Just look at the dependency registration of Zach's answer, and you'll understand what I'm talking about.
– User Aug 7 at 20:53 1 @User: Having the EmailNotificationService depend on an IFormatter implies that any string formatter would do just fine, while it can only work correctly with a formatter that can output mails. So what the EmailNotificationService is concerned it is not the same. While the IMailFormatter and the IFormatter have the same input and output types, the contract of the IMailFormatter is stronger, since it explicitly says what kind of string it returns, while IFormatter could return anything.
– Steven Aug 8 at 6:06.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.