All Projects → unosquare → tenantcore

unosquare / tenantcore

Licence: MIT License
TenantCore, OWIN multitenancy

Programming Languages

C#
18002 projects
Classic ASP
548 projects

Projects that are alternatives of or similar to tenantcore

appside
Multitenant environment automation.
Stars: ✭ 36 (+227.27%)
Mutual labels:  tenant
multi-tenant-support
Build a highly secure, no data leak, multi-tenant rails app
Stars: ✭ 27 (+145.45%)
Mutual labels:  tenant
multitenancy
A laravel package to provide multi-tenancy support
Stars: ✭ 20 (+81.82%)
Mutual labels:  tenant
multitenant
Multi-Tenant Spring Boot Application with separate databases using Hibernate and H2.
Stars: ✭ 15 (+36.36%)
Mutual labels:  tenant
go-saas
go data framework for saas(multi-tenancy)
Stars: ✭ 101 (+818.18%)
Mutual labels:  tenant
cortex-tenant
Prometheus remote write proxy that adds Cortex tenant ID based on metric labels
Stars: ✭ 60 (+445.45%)
Mutual labels:  tenant
go-poly-tenant
Go + Polymer MultiTenancy on AppEngine
Stars: ✭ 22 (+100%)
Mutual labels:  tenant
BlazorEFCoreMultitenant
Examples of multitenancy using EF Core and Blazor.
Stars: ✭ 67 (+509.09%)
Mutual labels:  tenant
Far-From-Home
A cross-platform mobile developed using Flutter and Firestore for House Rental Application with integrated payment module
Stars: ✭ 27 (+145.45%)
Mutual labels:  tenant
Multi Tenant
Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
Stars: ✭ 2,304 (+20845.45%)
Mutual labels:  tenant
Tenancy
Automatic multi-tenancy for Laravel. No code changes needed.
Stars: ✭ 2,133 (+19290.91%)
Mutual labels:  tenant

NuGet version Build Status Analytics

TenantCore

Important - This repository has been archived. We are not longer maintaining this project.

TenantCore is an OWIN Middleware that it can help to resolve tenants, a multitenancy middleware, by request's hostname for example or by any resolver. You can create your own Tenant's resolver or use the default one. The tenant can have a database connection string or any property that you need.

To start you need to setup the Resolver and Tenants in your OWIN AppBuilder, for example:

public void ConfigureAuth(IAppBuilder app)
{
    // SetUp Multitenancy with TenantCore
    var tenants = new List<ITenant>
    {
        new Tenant("local", "localhost", @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\local.mdf;Initial Catalog=local;Integrated Security=True"),
        new Tenant("sample", "sample.local", @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\sample.mdf;Initial Catalog=sample;Integrated Security=True"),
        new Tenant("fake", "fake.local", @"Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\fake.mdf;Initial Catalog=fake;Integrated Security=True")
    };
            
    app.UseTenantCore(new HostNameTenantResolver(tenants));

    // Configure the db context and user manager to use a single instance per request
    app.CreatePerOwinContext<ApplicationDbContext>(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);

    // And continue with your middleware and settings
}

If you want to have a database per tenant, you need to change your DbContext or IdentityDbContext to have a Create method with parameters:

public static ApplicationDbContext Create(IdentityFactoryOptions<ApplicationDbContext> options,
    IOwinContext context)
{
    return context.GetDbContext<ApplicationDbContext>();
}

The GetDbContext is an extension method in TenantCore, it will find the current Tenant and get the ConnectionString. The ConnectionString will be used with your DbContext, so be sure to have a constructor with connectionstring param like this:

public ApplicationDbContext(string connectionString)
            : base(connectionString, throwIfV1Schema: false) {}

Now in your ApiController you can use the Tenant or DbContext with some extension methods, for example:

[HttpGet, Route("register/{id}")]
public async Task<IHttpActionResult> Register(string id)
{
    // Gets the DbContext related to current Tenant
    var database = HttpContext.Current.GetDbContext<ApplicationDbContext>();
    // Gets the current Tenant
    var tenant = HttpContext.Current.GetCurrentTenant();
}
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].