我有这个接口,正在使用的具体类型屈指可数,如EmailFormatter
,TextMessageFormatter
等如何基于构造函数的参数名称注入适当的依赖
public interface IFormatter<T>
{
T Format(CompletedItem completedItem);
}
我遇到的问题是,我的EmailNotificationService
是我想注入EmailFormatter
。此服务的构造函数签名是public EmailNotificationService(IFormatter<string> emailFormatter)
。
我很确定我以前见过这件事,但是如何在Windsor注册这个,这样它会注入EmailFormatter
如果构造函数的参数名是emailFormatter
?
这是我的温莎注册码。
container.Register(Component.For<IFormatter<string>>().ImplementedBy<EmailFormatter>());
感谢您的回答。我正在寻找错误的东西。 :D – User
很高兴我能帮到你。 –