question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sharing connections, EfCoreStrategy and multitenancy

See original GitHub issue

Hi,

i read how i can share connection if i use multidbcontext in #1834 It works well in single database.

Is this multitenancy safe ? I mean, if i use tennant per database concept will code

options.DbContextOptions.UseSqlServer(options.ExistingConnection)

return existingconnection of current tennant ?

If so does it mean that options object is per tennant ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hikalkancommented, Jun 29, 2017

It’s not cached. The method below is called every time when a new database connection is needed:

            Configuration.Modules.AbpEfCore().AddDbContext<MyDbContext>(options =>
            {
                if (options.ExistingConnection != null)
                {
                    options.DbContextOptions.UseSqlServer(options.ExistingConnection);
                }
                else
                {
                    options.DbContextOptions.UseSqlServer(options.ConnectionString);
                }
            });

This class is responsible to select correct connection string based on current tenant: https://github.com/aspnetboilerplate/module-zero/blob/dev/src/Abp.ZeroCore.EntityFrameworkCore/Zero/EntityFrameworkCore/DbPerTenantConnectionStringResolver.cs

In brief, it works as expected 😃

0reactions
ismcagdascommented, Aug 21, 2017

thanks for the feedback @HossamZaki.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sharing Connections Furniture Bank - We Furnish Hope
Sharing Connections Furniture Bank has been furnishing hope to Northern Illinois individuals and families in crisis since 1986.
Read more >
Best Ef core strategy to run migrations for a lot of databases?
I am using Ef Core in a multi tenant database design project. To get the right connection string in every request I have...
Read more >
Multi-tenancy - EF Core
The multiple database version is implemented by passing a different connection string for each tenant. This can be configured at startup by ...
Read more >
Multitenancy with Cross-Tenant Users
We currently have a requirement to build a multi-tenant application that has cross-tenant users. That is the business data is separated by ...
Read more >
What is multi-tenancy? | Definition from TechTarget
Multi-tenancy applications can share the same users, displays, rules and database schemas. Users can customize the rules to an extent and the database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found