Search code examples
wcfnservicebusservicehost

NServiceBus and wcf ServiceHost


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)?


Solution

  • 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.