Giter Club home page Giter Club logo

finbuckle.multitenant's Introduction

Finbuckle Logo Finbuckle.MultiTenant 6.11.1

About Finbuckle.MultiTenant

Finbuckle.MultiTenant is an open-source multitenancy middleware library for .NET. It enables tenant resolution, per-tenant app behavior, and per-tenant data isolation. See https://www.finbuckle.com/multitenant for more details and documentation.

Current publish feed release:
Finbuckle.MultiTenant NuGet.org badge

Table of Contents

  1. What's New in Finbuckle.MultiTenant 6.11.1
  2. Quick Start
  3. Documentation
  4. Sample Projects
  5. Build and Test Status
  6. License
  7. .NET Foundation
  8. Code of Conduct
  9. Community
  10. Building from Source
  11. Running Unit Tests

What's New in Finbuckle.MultiTenant 6.11.1

Bug Fixes

See the changelog file for a full history of changes.

Quick Start

Finbuckle.MultiTenant is designed to be easy to use and follows standard .NET conventions as much as possible. This introduction assumes a standard ASP.NET Core use case, but any application using .NET dependency injection can work with the library.

Installation

First, install the Finbuckle.MultiTenant.AspNetCore NuGet package:

.NET Core CLI

$ dotnet add package Finbuckle.MultiTenant.AspNetCore

Basic Configuration

Next, in the app's service configuration call AddMultiTenant<T> and its various builder methods:

builder.Services.AddMultiTenant<TenantInfo>()
                .WithHostStrategy()
                .WithConfigurationStore();

Finally, in the app pipeline configuration call UseMultiTenant() before UseEndpoints(...) to register the middleware:

app.UseMultiTenant();
...
app.UseEndpoints(...);

That's all that is needed to get going. Let's breakdown each line:

builder.Services.AddMultiTenant<TenantInfo>()

This line registers the base services and designates TenantInfo as the class that will hold tenant information at runtime.

The type parameter for AddMultiTenant<T> must be an implementation of ITenantInfo and holds basic information about the tenant such as its name and an identifier. TenantInfo is provided as a basic implementation, but a custom implementation can be used if more properties are needed.

See Core Concepts for more information on ITenantInfo.

.WithHostStrategy()

The line tells the app that our "strategy" to determine the request tenant will be to look at the request host, which defaults to the extracting the subdomain as a tenant identifier.

See Strategies for more information.

.WithConfigurationStore()

This line tells the app that information for all tenants are in the appsettings.json file used for app configuration. If a tenant in the store has the identifier found by the strategy, the tenant will be successfully resolved for the current request.

See Stores for more information.

Finbuckle.MultiTenant comes with a collection of strategies and store types that can be mixed and matched in various ways.

app.UseMultiTenant()

This line configures the middleware which resolves the tenant using the registered strategies, stores, and other settings. Be sure to call it before calling UseEndpoints() and other middleware which will use per-tenant functionality, e.g. UseAuthentication().

Basic Usage

With the services and middleware configured, access information for the current tenant from the TenantInfo property on the MultiTenantContext<T> object accessed from the GetMultiTenantContext<T> extension method:

var tenantInfo = HttpContext.GetMultiTenantContext<TenantInfo>().TenantInfo;

if(tenantInfo != null)
{
    var tenantId = tenantInfo.Id;
    var identifier = tenantInfo.Identifier;
    var name = tenantInfo.Name;
}

The type of the TenantInfo property depends on the type passed when calling AddMultiTenant<T> during configuration. If the current tenant could not be determined then TenantInfo will be null.

The ITenantInfo instance and/or the typed instance are also available directly through dependency injection.

See Configuration and Usage for more information.

Documentation

The library builds on this basic functionality to provide a variety of higher level features. See the documentation for more details:

Sample Projects

A variety of sample projects are available in the repository.

Build and Test Status

Build Status Linux 6.0
Build Status Linux 6.0

Build Status MacOS 6.0
Build Status MacOS 6.0

Build Status Windows 6.0
Build Status Windows 6.0

License

This project uses the Apache 2.0 license. See LICENSE file for license information.

.NET Foundation

This project is supported by the .NET Foundation.

Code of Conduct

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information see the .NET Foundation Code of Conduct or the CONTRIBUTING.md file.

Community

Check out the GitHub repository to ask a question, make a request, or peruse the code!

Building from Source

From the command line clone the git repository, cd into the new directory, and compile with dotnet build.

$ git clone https://github.com/Finbuckle/Finbuckle.MultiTenant.git
$ cd Finbuckle.MultiTenant
Cloning into 'Finbuckle.MultiTenant'...
<output omitted>
$ cd Finbuckle.MultiTenant
$ dotnet build

Running Unit Tests

Run the unit tests from the command line with dotnet test from the solution directory.

$ dotnet test

finbuckle.multitenant's People

Contributors

acasciani avatar andrewtriestocode avatar blittable avatar bobbyangers avatar brockallen avatar cacpgomes avatar chernihiv avatar danjus10 avatar fossbrandon avatar gordonblahut avatar harisbotic avatar kakone avatar lahma avatar lamarlugli avatar lionelvallet avatar mesfinmo avatar mphill avatar mseada94 avatar natelaff avatar nbarbettini avatar onurkanbakirci avatar rchamorro avatar rikbosch avatar romanky avatar semantic-release-bot avatar sharepointradi avatar valks avatar willl avatar zahidcakici avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.