joaope / Autofac.AspNetCore.Multitenant

Enables multitenant dependency injection support for ASP.NET Core.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Autofac.AspNetCore.Multitenant

ASP.NET Core support for multitenant DI via Autofac.Multitenant.

Build status codecov Open in Visual Studio Code

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

Why Use This?

ASP.NET Core default RequestServicesContainerMiddleware is where the per-request lifetime scope usually gets generated. However, its constructor is where it wants the IServiceScopeFactory that will be used later during the request to create the request lifetime scope.

Unfortunately, that means the IServiceScopeFactory is created/resolved at the point when the request comes in, long before an HttpContext is set in any IHttpContextAccessor. The result is the scope factory ends up coming from the default tenant scope, before a tenant can be identified, and per-request services will later all come from the default tenant. Multitenancy fails.

This package provides a different request services middleware that ensures the IHttpContextAccessor.HttpContext is set and defers creation of the request lifetime scope until as late as possible so anything needed for tenant identification can be established.

Reference

About

Enables multitenant dependency injection support for ASP.NET Core.

License:MIT License


Languages

Language:C# 79.3%Language:PowerShell 20.7%