Skip to content

Commit

Permalink
chore: docs tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewTriesToCode committed Nov 9, 2024
1 parent 5611c60 commit c0dc259
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions docs/EFCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,25 @@ database context instance for a specific tenant.

```csharp
// create or otherwise obtain a tenant info instance
var tenantInfo = new MyTenantInfo(...);
using var tenantInfo = new MyTenantInfo(...);

// create a database context instance for the tenant
var tenantDbContext = MultiTenantDbContext.Create<AppMultiTenantDbContext, AppTenantInfo>(tenantInfo);
using var tenantDbContext = MultiTenantDbContext.Create<AppMultiTenantDbContext, AppTenantInfo>(tenantInfo);

// create a database context instance for the tenant with an instance of DbOptions<AppMultiTenantDbContext>
var tenantDbContextWithOptions = MultiTenantDbContext.Create<AppMultiTenantDbContext, AppTenantInfo>(tenantInfo,
dbOptions);

// loop through a bunch of tenant instances
foreach (var tenant in tenants)
{
using var tenantDbContext = MultiTenantDbContext.Create<AppMultiTenantDbContext, AppTenantInfo>(tenant);
// do something with the database context
}
```

Make sure to dispose of the database context instance when it is no longer needed, or better yet use a `using` block.
Make sure to dispose of the database context instance when it is no longer needed, or better yet use a `using` block
or variable.
This method will work for any database context class expecting a `IMultiTenantContextAccessor` in its constructor and an
options DbContextOptions<T> in its constructor.

Expand Down

0 comments on commit c0dc259

Please sign in to comment.