From c0dc259835a54dda156d352a46fc26d0a0756726 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Fri, 8 Nov 2024 18:16:21 -0700 Subject: [PATCH] chore: docs tweak --- docs/EFCore.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/EFCore.md b/docs/EFCore.md index eb30e005..7154574f 100644 --- a/docs/EFCore.md +++ b/docs/EFCore.md @@ -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(tenantInfo); +using var tenantDbContext = MultiTenantDbContext.Create(tenantInfo); // create a database context instance for the tenant with an instance of DbOptions var tenantDbContextWithOptions = MultiTenantDbContext.Create(tenantInfo, dbOptions); + +// loop through a bunch of tenant instances +foreach (var tenant in tenants) +{ + using var tenantDbContext = MultiTenantDbContext.Create(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 in its constructor.