From d682cc0f290961a6ef332e0f88a04ed370f326f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 6 Feb 2023 10:52:09 +0300 Subject: [PATCH] Document #15335: Make ReplaceDbContext supports multi-tenancy --- docs/en/Entity-Framework-Core.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/en/Entity-Framework-Core.md b/docs/en/Entity-Framework-Core.md index 568623a15d..fc17ddcd49 100644 --- a/docs/en/Entity-Framework-Core.md +++ b/docs/en/Entity-Framework-Core.md @@ -834,7 +834,7 @@ One advantage of using an interface for a DbContext is then it will be replaceab Once you properly define and use an interface for DbContext, then any other implementation can use the following ways to replace it: -**ReplaceDbContextAttribute** +#### ReplaceDbContext Attribute ```csharp [ReplaceDbContext(typeof(IBookStoreDbContext))] @@ -844,7 +844,7 @@ public class OtherDbContext : AbpDbContext, IBookStoreDbContext } ``` -**ReplaceDbContext option** +#### ReplaceDbContext Option ````csharp context.Services.AddAbpDbContext(options => @@ -856,6 +856,22 @@ context.Services.AddAbpDbContext(options => In this example, `OtherDbContext` implements `IBookStoreDbContext`. This feature allows you to have multiple DbContext (one per module) on development, but single DbContext (implements all interfaces of all DbContexts) on runtime. +#### Replacing with Multi-Tenancy + +It is also possible to replace a DbContext based on the [multi-tenancy](Multi-Tenancy.md) side. `ReplaceDbContext` attribute and `ReplaceDbContext` method can get a `MultiTenancySides` option with a default value of `MultiTenancySides.Both`. + +**Example:** Replace DbContext only for tenants, using the `ReplaceDbContext` attribute + +````csharp +[ReplaceDbContext(typeof(IBookStoreDbContext), MultiTenancySides.Tenant)] +```` + +**Example:** Replace DbContext only for the host side, using the `ReplaceDbContext` method + +````csharp +options.ReplaceDbContext(MultiTenancySides.Host); +```` + ### Split Queries ABP enables [split queries](https://docs.microsoft.com/en-us/ef/core/querying/single-split-queries) globally by default for better performance. You can change it as needed.