Browse Source

Document #15335: Make ReplaceDbContext supports multi-tenancy

pull/15607/head
Halil İbrahim Kalkan 3 years ago
parent
commit
d682cc0f29
  1. 20
      docs/en/Entity-Framework-Core.md

20
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<OtherDbContext>, IBookStoreDbContext
}
```
**ReplaceDbContext option**
#### ReplaceDbContext Option
````csharp
context.Services.AddAbpDbContext<OtherDbContext>(options =>
@ -856,6 +856,22 @@ context.Services.AddAbpDbContext<OtherDbContext>(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<IBookStoreDbContext>(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.

Loading…
Cancel
Save