Skip to content

Enables multitenant dependency injection support for ASP.NET Core.

License

Notifications You must be signed in to change notification settings

alsami/Autofac.AspNetCore.Multitenant

 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 79.3%
  • PowerShell 20.7%