我所见过的每个nServiceBus示例都使用了具体的类来进行IOC属性注入。如何注册接口?在下面的示例中,如何注册ISmtpClient以返回SmtpClientProxy (我创建的一个具体类)?
public class EmailNotificationMessageHandler : IHandleMessages<EmailNotificationMessage>
{
public ISmtpClient Smtp { get; set; }
public void Handle(EmailNotificationMessage message)
{
//this.Smtp = new SmtpClient("localhost", 25);
this.Smtp.SendAsync(message.FromAddress, message.ToAddress, message.Subject, message.Body, message.Id);
}
}我的配置如下所示,但是我不知道如何使用具体的类型(我不想要Singleton)
Configure.With().CastleWindsorBuilder().JsonSerializer();
Configure.Instance.Configurer.ConfigureComponent<ISmtpClient>(DependencyLifecycle.InstancePerCall);另外,有没有办法访问实际的容器(在我的例子中是Windsor),以完成我想要的任何其他注册工作?
发布于 2012-03-14 05:28:10
您可以将要使用的容器传递给nServiceBus,并且可以在以下位置引用它:
_container = new WindsorContainer();
Configure.With().CastleWindsorBuilder(_container).JsonSerializer();
_container.AddComponent<ISmtpClient, CustomSmtpClient>();https://stackoverflow.com/questions/9692304
复制相似问题