NServiceBus 和 wcf ServiceHost
我有一个 wcf ServiceHost,它必须向 IBus 发布消息。
如何从主机类(由 wcf 实例化)优雅地访问 IBus?
I have a wcf ServiceHost which has to publish a message to the IBus.
How do I gracefully gain access to the IBus from the host class (which is instatiated by wcf)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以让您更干净地访问 IBus。将静态类命名为您想要的任意名称。不必担心共享 IBus 实例 - 总线是完全线程安全的。
This should provide access to the IBus for you a bit more cleanly. Name the static class whatever you want. Don't worry about sharing the IBus instance - the bus is fully thread-safe.
我们所做的(可能有更简洁的方法)是我们有一个实现 IWantToRunAtStartup 的类。我们为该类提供一个 IBus 属性,该属性由内置于 NServiceBus 中的 DI 容器初始化。
然后我们实例化我们的 Web 服务类(具有 ServiceBehavior 属性的类),从启动类传入 IBus 实例。然后我们从该实例实例化我们的 ServiceHost。
感觉有点笨拙,但我们没有遇到任何麻烦。希望有帮助。
What we do (there may be a cleaner way) is we have a class that implements IWantToRunAtStartup. We give that class an IBus property that gets initialized by the DI container built into NServiceBus.
Then we instantiate our Web service class (the one that has the ServiceBehavior attribute), passing in the IBus instance from the start-up class. Then we instantiate our ServiceHost from that instance.
It feels a little kludgy, but we haven't had any trouble with it. Hope that helps.