Bootproject.Multitenancy.Core 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Bootproject.Multitenancy.Core --version 2.1.0                
NuGet\Install-Package Bootproject.Multitenancy.Core -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Bootproject.Multitenancy.Core" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Bootproject.Multitenancy.Core --version 2.1.0                
#r "nuget: Bootproject.Multitenancy.Core, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Bootproject.Multitenancy.Core as a Cake Addin
#addin nuget:?package=Bootproject.Multitenancy.Core&version=2.1.0

// Install Bootproject.Multitenancy.Core as a Cake Tool
#tool nuget:?package=Bootproject.Multitenancy.Core&version=2.1.0                

Bootproject.Multitenancy (Core 2.2)

This project is an extension of nHibernate's ISessionFactory and makes it incredible easy to use multiple sessions within the same application. It's used to define different domains and their databases. Uses MySql as database.

Since the previous versions in .Net 4.6 this is more lightweighted, without
lack of functionallity.

Built in model creation. When adding a new model its automatically gets replicated in database.

Setup

Reference Multitenancy to your project, and in Startup.cs add:

//Add (in ConfigureServices)
services.AddMultitenancy();

//And (in Configure before app.UseMvc())
app.UseMultitenancy();

Configuration

Add "DomainConfiguration" section to appsettings.json like the example below:

{
  "Logging": {
	"LogLevel": {
	  "Default": "Warning"
	}
  },
  "DomainConfiguration": {
	"Domains": [
	  {
		"Name": "bootproject",
		"Dns": "localhost,bootproject.net",
		"ConnectionString": "server=localhost;port=3306;database=test1;uid=root;password=1234"
	  },
	  {
		"Name": "example",
		"Dns": "example.com",
		"ConnectionString": "server=localhost;port=3306;database=test2;uid=root;password=1234"
	  }
	]
  },
  "AllowedHosts": "*"
}

Note: - Default domain will always be localhost.

How to use

Adding a model:	

[Table("Pages")]
public class Page : IEntity
{
	public virtual int Id{ get; set;}
	public virtual string Title{ get; set}
	//.....
}

//In controller
private readonly ISession Session; 

public HomeController()
{
    Session = Host.Open();
}

public IActionResult Index()
{
    var model = Session.All<Page>();

    if (!model.Any()) { 
        var page = new Page { Id=1, Title="Start" };
        Session.Save<Page>(page);
        Session.Flush();
    }
    return View(model);
}

Caching

In Bootproject.Multitenancy project theres built in cache of Entities. When for eg. calling All<T>.First(t=> t.Id==1) wich makes a call for all T could be a performance issue, but since its already in the cache, this is not a problem.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.2 is compatible.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.3.1 715 12/12/2019
2.1.0 1,125 8/7/2019

First release of Bootproject.Multitenancy for ,net Core 2.2