Configuration order for persistence

Component: NServiceBus
NuGet Package NServiceBus (5.x)

When configuring persistence order is very important. The last configured persistence option wins.

Example 1

In this example the last configuration option will override all previous options.

5.x NServiceBus
busConfiguration.UsePersistence<NHibernatePersistence>()
    .For(Storage.Outbox);

busConfiguration.UsePersistence<InMemoryPersistence>()
    .For(Storage.GatewayDeduplication);

// This one will override the above settings
busConfiguration.UsePersistence<RavenDBPersistence>();
5.2 NServiceBus
busConfiguration.UsePersistence<NHibernatePersistence, StorageType.Outbox>();

busConfiguration.UsePersistence<InMemoryPersistence, StorageType.GatewayDeduplication>();

// This one will override the above settings
busConfiguration.UsePersistence<RavenDBPersistence>();

Example 2

In this example all configuration options are explicit.

5.x NServiceBus
busConfiguration.UsePersistence<NHibernatePersistence>()
    .For(Storage.Outbox);

busConfiguration.UsePersistence<InMemoryPersistence>()
    .For(Storage.GatewayDeduplication);

busConfiguration.UsePersistence<RavenDBPersistence>()
    .For(Storage.Sagas,
        Storage.Subscriptions,
        Storage.Timeouts);
5.2 NServiceBus
busConfiguration.UsePersistence<NHibernatePersistence, StorageType.Outbox>();

busConfiguration.UsePersistence<InMemoryPersistence, StorageType.GatewayDeduplication>();

busConfiguration.UsePersistence<RavenDBPersistence, StorageType.Sagas>();
busConfiguration.UsePersistence<RavenDBPersistence, StorageType.Subscriptions>();
busConfiguration.UsePersistence<RavenDBPersistence, StorageType.Timeouts>();

Example 3

This example sets the default persistence first thing and then overrides more explicit options.

5.x NServiceBus
busConfiguration.UsePersistence<RavenDBPersistence>();

busConfiguration.UsePersistence<NHibernatePersistence>()
    .For(Storage.Outbox);

busConfiguration.UsePersistence<InMemoryPersistence>()
    .For(Storage.GatewayDeduplication);
5.2 NServiceBus
busConfiguration.UsePersistence<RavenDBPersistence>();

busConfiguration.UsePersistence<NHibernatePersistence, StorageType.Outbox>();

busConfiguration.UsePersistence<InMemoryPersistence, StorageType.GatewayDeduplication>();

Last modified