All Projects → JeremyLikness → BlazorEFCoreMultitenant

JeremyLikness / BlazorEFCoreMultitenant

Licence: MIT license
Examples of multitenancy using EF Core and Blazor.

Programming Languages

C#
18002 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to BlazorEFCoreMultitenant

EntityFrameworkCore.Triggered
Triggers for EFCore. Respond to changes in your DbContext before and after they are committed to the database.
Stars: ✭ 361 (+438.81%)
Mutual labels:  entity-framework, efcore, entity-framework-core
Blazor-CRUD
Simple CRUD application using C#/Blazor
Stars: ✭ 25 (-62.69%)
Mutual labels:  entity-framework, entity-framework-core, blazor
Blazorwasmefcoreexample
Example of a Blazor WebAssembly project that uses Entity Framework Core on the server for data access.
Stars: ✭ 105 (+56.72%)
Mutual labels:  entity-framework, entity-framework-core
Maikebing.entityframeworkcore.taos
Entity, Framework, EF, Core, Data, O/RM, entity-framework-core,TDengine
Stars: ✭ 113 (+68.66%)
Mutual labels:  entity-framework, entity-framework-core
LinqBuilder
LinqBuilder is an advanced implementation of the specification pattern specifically targeting LINQ query generation.
Stars: ✭ 34 (-49.25%)
Mutual labels:  entity-framework, entity-framework-core
Localization
🌏 Database Resource Localization for .NET Core with Entity Framework and In Memory Cache
Stars: ✭ 68 (+1.49%)
Mutual labels:  entity-framework, entity-framework-core
Entityframework.commontools
Extensions, Auditing, Concurrency Checks, JSON properties and Transaction Logs for EntityFramework and EFCore
Stars: ✭ 82 (+22.39%)
Mutual labels:  entity-framework, entity-framework-core
Entityframework Plus
Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
Stars: ✭ 1,848 (+2658.21%)
Mutual labels:  entity-framework, entity-framework-core
Efcorepowertools
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization for EF Core
Stars: ✭ 774 (+1055.22%)
Mutual labels:  entity-framework, entity-framework-core
Linq2db.entityframeworkcore
Bring power of Linq To DB to Entity Framework Core projects
Stars: ✭ 166 (+147.76%)
Mutual labels:  entity-framework, entity-framework-core
Pomelo.entityframeworkcore.mysql
Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
Stars: ✭ 2,099 (+3032.84%)
Mutual labels:  entity-framework, entity-framework-core
Onion Architecture Asp.net Core
WhiteApp API solution template which is built on Onion Architecture with all essential feature using .NET 5!
Stars: ✭ 196 (+192.54%)
Mutual labels:  entity-framework, entity-framework-core
Entityframework.lazyloading
LazyLoading for EF Core
Stars: ✭ 23 (-65.67%)
Mutual labels:  entity-framework, entity-framework-core
Entityframework.docs
Documentation for Entity Framework Core and Entity Framework 6
Stars: ✭ 888 (+1225.37%)
Mutual labels:  entity-framework, entity-framework-core
Sample Dotnet Core Cqrs Api
Sample .NET Core REST API CQRS implementation with raw SQL and DDD using Clean Architecture.
Stars: ✭ 1,273 (+1800%)
Mutual labels:  entity-framework, entity-framework-core
Efcore.pg
Entity Framework Core provider for PostgreSQL
Stars: ✭ 838 (+1150.75%)
Mutual labels:  entity-framework, entity-framework-core
Dotnetlabs
.NET Labs -- Show Me the Tips and Tricks and Code
Stars: ✭ 135 (+101.49%)
Mutual labels:  entity-framework, entity-framework-core
Entityframework.exceptions
Handle database errors easily when working with Entity Framework Core. Supports SQLServer, PostgreSQL, SQLite, Oracle and MySql
Stars: ✭ 266 (+297.01%)
Mutual labels:  entity-framework, entity-framework-core
Efsecondlevelcache.core
Entity Framework Core Second Level Caching Library
Stars: ✭ 300 (+347.76%)
Mutual labels:  entity-framework, entity-framework-core
Dntidentity
A highly customized sample of the ASP.NET Core Identity
Stars: ✭ 145 (+116.42%)
Mutual labels:  entity-framework, entity-framework-core

Blazor EF Core Multitenant

Examples of using multi-tenancy with Entity Framework Core in a Blazor app using the data context factory.

Read the related, detailed blog post here.

Quickstart

  1. Clone the repository: git clone https://github.com/JeremyLikness/BlazorEFCoreMultitenant
  2. Launch the app
    1. Open in VS Code and hit F5, or
    2. Open in Visual Studio and hit F5, or
    3. From a command line at the root of the project, type dotnet run
  3. The databases ship with the project. If you need to create them or wish to recreate them, delete the .sqlite files then use the button on the main page of the app to regenerate them.
  4. Select your tenant and navigate to the multidatabase or single database solutions.

The database simply tracks methods and parameters. The ParentType is used for the "tenant."

Notes

This example shows two different solutions. Both configure the context in a way that makes the tenancy ambient to the consumer. The code simply loads the list of DataMethod instances without filters, but only the tenant-specific items are returned. This is because the single database approach uses a global query filter and the multiple database approach uses a differnet database altogether for each tenant.

Single Database

For a single database, the column to hold tenant in this example is ParentType. It could be a tenantId or some other field. The factory is set to Scoped instead of singleton so it can acquire the instance of TenantProvider that is running for the current user. This will cache the options, which is fine for a single database. It also caches the instance of of the TenantProvider. This is the same one use in the rest of the application, so the OnModelBuilding override is able to add a global filter based on the current tenant.

Multiple Databases

For multiple databases, the database is named after the tenant so there is a one-to-one mapping. Instead of using a global filter, the tenant is used to build the connection string and passed back. To allow the case when a user might change their tenant "on the fly" the factory is scoped as Transient instead so the tenant is always re-evaluated in case it changes.

Performance

You can use the benchmark project to evaluate performance. Be sure to run it in Release mode:

dotnet run -c Release

Here are the results on my laptop:

Method Mean Error StdDev
SingleContext 1.134 us 0.0224 us 0.0249 us
MultipleContext 3.087 us 0.0608 us 0.0964 us

Although the Transient is slower than Scoped, it is still a fast operation. Another way to think about 3us is 333k requests per second.


Feedback? Questions? Message me on Twitter: @JeremyLikness

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].