nservicebusnservicebus-sagas

In ServiceMatrix, is it possible to 'ConvertToSaga' an endpoint which publishes/subscribes event messages rather than command messages?


I've got a solution with 4 NSB host endpoints which were created using ServiceMatrix and I want to use them within a saga.

I know how to Convert To Saga from a command and that works fine in a test project. What I don't understand is how I can do the same thing with published events, as the menu option is not available. Is it possible to do this using ServiceMatrix ?

I have tried to implement the changes by hand by following this tutorial and observing the changes that were made to my test project when I Converted To Saga.

It builds ok but throws an error within the framework when running:

System.InvalidOperationException was unhandled Message: An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll

Additional information: No IBus instance available, please configure one and also verify that you're not defining your own Bus property in your saga since that hides the one in the base class

I'm using VS2013 and ServiceBus 5.

UPDATE: I commented out the inherited IHandleMessages<> interface and public IBus Bus property from the generated code and it runs without this error. I'm not happy doing this, as the next design change using the tool will overwrite these fixes.


Solution

  • In your command handler you usually have a property of type IBus that is injected to the handler class either by property injection or constructor injection.

    When you move from a command handler to a Saga, you need to remove your IBus property from the handler. Saga base class has a Bus property that you should use instead. This property is populated for you automatically, you should not care about this. This is exactly what this exception is telling you.