使用AutoFac注册对象

时间:2014-09-09 13:54:06

标签: autofac rebus

我正在使用Rebus。在AutofacContainerAdapter(https://github.com/rebus-org/Rebus/blob/master/src/Rebus.Autofac/AutofacContainerAdapter.cs)中,他们调用以下代码行:

builder.Register(a => MessageContext.GetCurrent()).ExternallyOwned();

如何设置我的MessageHandler构造函数以便Autofac可以找回这种类型?如果我理解正确,当我在构造函数中使用IMessageContext时,它将不会被传递,因为上面的代码中没有.As<IMessageContext>()

1 个答案:

答案 0 :(得分:1)

观察:https://github.com/rebus-org/Rebus/blob/master/src/Rebus/MessageContext.cs显示:

public static IMessageContext GetCurrent()
{
}

因此注册为IMessageContext。如果没有明确说明,lambda注册会隐式注册为lambda的返回类型。

相关问题