You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: samples/multi-tenant/nhibernate/sample.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: NHibernate persistence in multi-tenant systems
3
3
summary: Configure NHibernate persistence to support multi-tenant scenarios.
4
-
reviewed: 2024-03-01
4
+
reviewed: 2025-12-23
5
5
component: NHibernate
6
6
related:
7
7
- persistence/nhibernate
@@ -10,7 +10,7 @@ related:
10
10
11
11
This sample demonstrates how to configure NHibernate persistence to store tenant-specific data in separate catalogs for each tenant. The tenant-specific information includes saga state and business entities that are accessed using [NServiceBus-managed session](/persistence/nhibernate/accessing-data.md).
12
12
13
-
This sample uses [Outbox](/nservicebus/outbox/) to guarantee consistency between the saga state and the business entity. Outbox and timeout data are stored in a dedicated catalog shared by all tenants.
13
+
This sample uses [Outbox](/nservicebus/outbox/) to guarantee consistency between the saga state and the business entity. Outbox data is stored in a dedicated catalog shared by all tenants.
14
14
15
15
The sample assumes the tenant information is passed as a custom message header `tenant_id`.
16
16
@@ -36,7 +36,7 @@ The default NHibernate persistence installers create all schema objects in a sin
36
36
37
37
snippet: CreateSchema
38
38
39
-
The above code ensures that business entity and saga tables are created in the tenant databases while the timeouts and outbox are in the shared database.
39
+
The above code ensures that business entity and saga tables are created in the tenant databases while the outbox table is in the shared database.
40
40
41
41
Because the outbox table is stored in the shared catalog, the NHibernate persistence cannot access it when using the tenant connection string. Synonyms (a feature of SQL Server) provide a way to solve this problem. The following code creates synonyms for the `OutboxRecord` table in both tenant databases. These synonyms instruct the query processor to use the outbox table in the shared database whenever it encounters a reference to `OutboxRecord`.
To allow database isolation between tenants, the connection to the database needs to be created based on the message being processed. This requires the cooperation of two components:
54
54
55
-
* A behavior that inspects an incoming message and extracts the tenant's information
55
+
* A behavior that inspects an incoming message and extracts the tenant's information
56
56
* A custom `ConnectionProvider` for NHibernate
57
57
58
58
The custom connection provider has to be registered with NHibernate
0 commit comments