通过 MSMQ Simple Injector Lifestyle 自托管 WCF

Self Hosted WCF via MSMQ Simple Injector Lifestyle

我正在通过 MSMQ 绑定使用 WCF(自托管)并希望使用 Per WCF request lifestyle with SimpleInjector。我将我的代码设置为:

Dim httpLifecycle = New SimpleInjector.Integration.Wcf.WcfOperationLifestyle(True)
container.Register(of ISomeType, SomeType)(httpLifecycle)

在 MSMQ 上,这不起作用,因为我收到错误:

The dependency resolver for the web services host failed to initialize: SimpleInjector.ActivationException: The registered delegate for type ILoader threw an exception. The ISomeType is registered as 'WCF Operation' lifestyle, but the instance is requested outside the context of a WCF Operation.

WCF 是否可以请求生活方式与 MSMQ 一起工作?

我最终使用了每个执行范围并在 WCF 服务操作本身中定义了该范围。通过这种方式确定范围,它确保了依赖项在我需要时打开和关闭。

我需要包括 execution context scoping