0

In NSB 5, how do I correctly configure NSB with autofac container with one IDocumentStore for NSB data and a separate IDocumentStore for application data? I've pasted the relevant part of EndpointConfig below:

            // Raven DataStore for Freight system
        var appDataStore = new DocumentStore { 
            ConnectionStringName = "RavenDB",
            DefaultDatabase = "ApplicationData"
        };
        appDataStore .Initialize();

        // Raven DataStore for NServiceBus
        var nsbDataStore = new DocumentStore
        {
            ConnectionStringName = "NServiceBus.Persistence",
            DefaultDatabase = "BookingProcessing"
        };
        nsbDataStore.Initialize();

        // Set up and build AutoFac container
        var builder = new ContainerBuilder();
        builder.RegisterInstance<DocumentStore>(appDataStore ).As<IDocumentStore>().SingleInstance();
        var container = builder.Build();

        // Set up NServiceBus
        configuration.UseContainer<AutofacBuilder>(customizations => customizations.ExistingLifetimeScope(container));
        configuration.UsePersistence<RavenDBPersistence>().SetDefaultDocumentStore(nsbDataStore);

I know this isn't working since I had problems storing sagas in another question. The SagaPersister tried to persist saga in appDataStore, but the Timeout Messages was persisted in nsbDataStore.

Community
  • 1
  • 1
Trygve
  • 2,445
  • 1
  • 19
  • 23

2 Answers2

2

This issue is now fixed in NServiceBus.RavenDB v2.0.1

John Simons
  • 4,288
  • 23
  • 41
1

This is a sample for 4.x using unit of work, If you use

Look here to see how you can implement IManageUnitsOfWork

The Init is here Look here for the usage

will this help?

Sean Farmar
  • 2,254
  • 13
  • 10
  • Thanks. I took a look at a similar example from Andreas Öhlund earlier. Both examples use only a single DocumentStore, right? So userdata and NSB data are using the same datastore. I'm trying to use two different stores... And btw, u'r sample doesn't compile: The type 'StructureMap.IContainer' is defined in an assembly that is not referenced. You must add a reference to assembly 'StructureMap, Version=2.6.4.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223'. I upgraded structuremap to the latest NuGet version, no luck – Trygve Nov 10 '14 at 09:39
  • Let me get the sample updated to reflect your use case and use autofac instead. – Sean Farmar Nov 10 '14 at 11:07
  • 2
    Iv'e added a [V5 with autofac sample](https://github.com/sfarmar/Samples/tree/master/DIUnitOfWorkV5Autofac), let me know if that work for you... – Sean Farmar Nov 10 '14 at 18:02
  • (Also commented in NSB group). The sample works, but when I implemented a saga it would still store saga data in the application database, not the database defined by the NSB endpoint. Is this by design? I would prefer to keep everything NSB in the same database away from my application data. Although arguably the saga IS application data... – Trygve Nov 12 '14 at 10:29
  • 1
    It's a bug, and the solution (provided by Szymon) is here: https://groups.google.com/d/msg/particularsoftware/B0LSO5MYbpo/7s9toKFlk0QJ – Sean Farmar Nov 12 '14 at 14:48