NServiceBus
NServiceBus copied to clipboard
Add support for multi-tenant systems with shared DB and discriminator columns
This issue was transferred from a private repository
The multi-tenant with shared DB and discriminator columns approach is probably the most used by SaaS providers when approaching a new business. In such scenario their customers are probably small businesses with low volumes of data. In such a case it might not be worth going directly to the next level (separate storage) and it's worth supporting shared DB and discriminator columns.
Support for such scenario can implemented in a non-breaking way by leveraging the ContextBag passed to ISagaPersister and IFindSagas. It's enough to augment a persister configuration with something like:
var persister = endpointConfig.UserPerisistence<Something>();
persister.UseMultiTenantDiscriminator( discriminatorColumnName, discrimnatorValueKeyName );
and then change the internal persister implementation so that:
- if the above configuration is set
- a behavior in the pipeline sets the discriminator value in the
ContextBag - when the persister is invoked
- discriminator value is extracted from the
ContextBag - and defined column name is used to configure the query issued to underlying storage