2

I have an endpoint, called UploadService, that contains a saga started by a command defined in another assembly. The commands in that assembly are registered in the endpoint's initialization via the following lines:

public class EndpointInitialization : IWantCustomInitialization
    {
        public void Init()
        {
            NServiceBus.Configure.Features.Enable<NServiceBus.Features.Sagas>();

            NServiceBus.Configure.With()
              .Log4Net()
              .UseInMemoryTimeoutPersister()
              .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands"))
              .DefiningMessagesAs(t => t.Namespace != null && t.Namespace.Contains("Messages"))
              .UnicastBus()
                 .ImpersonateSender(false)
              .CreateBus()
              .Start();
        }
    }

However, when start the endpoint via Debug->Start new instance, NServiceBus.Core throws the following exception:

"The saga 'MySaga' implements 'IHandleMessages`1' but the message type 'MyCommand' is not classified as a message. You should either use 'Unobtrusive Mode Messages' or the message should implement either 'IMessage', 'IEvent' or 'ICommand'."

I have a seprate endpoint which references the same Commands assembly, and has custom initialization defined the same way, and starts up just fine (only difference is the other endpoint does not use sagas).

UPDATE: I'm using NServiceBus 4.2

Andrew Church
  • 1,391
  • 11
  • 13
  • Can you please create an issue in github and send us a repro ? – John Simons Nov 06 '13 at 20:38
  • Will do - perhaps I'm using this feature wrong, but the issue seems to be with having my message definitions in a custom initialization class that is separate from my endpoint config. When I specify my initialization in the same class as my endpoint config, it starts up fine. – Andrew Church Nov 07 '13 at 13:57

1 Answers1

2

Yes. Sagas do work in Unobtrusive mode. Call your initialization code in the class that implements IConfigureThisEndpoint, where the instance of the Bus is created and that should fix the problem for you.

For example:

 public class EndpointConfig: IConfigureThisEndpoint, AsA_Publisher,  IWantCustomInitialization
{
    public void Init()
    {
        var container = new WindsorContainer();
        Configure.With()
            .CastleWindsorBuilder(container)
            .FileShareDataBus(@"..\..\..\DataBusShare\")
            .DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus"))
            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands"))
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith("Events"))
            .DefiningMessagesAs(t => t.Namespace == "Messages")
            .DefiningEncryptedPropertiesAs(p => p.Name.StartsWith("Encrypted"))
            .UseNHibernateSagaPersister()
            .UseNHibernateTimeoutPersister()
            .UseNHibernateSubscriptionPersister();
        Configure.Serialization.Json();

    }
}
Indu Alagarsamy
  • 449
  • 2
  • 4
  • Interesting. This did the trick, however, isn't NSB designed to work having my custom initialization in a separate class? Having my message definitions in a separate custom initialization class doesn't seem to be a problem for endpoints that don't use sagas. – Andrew Church Nov 07 '13 at 13:55
  • You can have multiple classes that implement IWantCustomInitialization without any issues. However in these classes to refer to the Bus, you'd be using Configure.Instance. and not Configure.With() – Indu Alagarsamy Nov 07 '13 at 17:26
  • Tried using Configure.Instance in a seperate class, still got the same exception. Putting my init in my endpoint config seems to be the way to resolve this one. – Andrew Church Nov 07 '13 at 18:44