mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
865 B
32 lines
865 B
using System;
|
|
using System.Threading;
|
|
using Volo.DependencyInjection;
|
|
|
|
namespace Volo.Abp.MultiTenancy
|
|
{
|
|
public class AsyncLocalTenantScopeProvider : ITenantScopeProvider, ISingletonDependency
|
|
{
|
|
public TenantScope CurrentScope
|
|
{
|
|
get { return _currentScope.Value; }
|
|
private set { _currentScope.Value = value; }
|
|
}
|
|
|
|
private readonly AsyncLocal<TenantScope> _currentScope;
|
|
|
|
public AsyncLocalTenantScopeProvider()
|
|
{
|
|
_currentScope = new AsyncLocal<TenantScope>();
|
|
}
|
|
|
|
public IDisposable EnterScope(TenantInformation tenant)
|
|
{
|
|
var parentScope = CurrentScope;
|
|
CurrentScope = new TenantScope(tenant);
|
|
return new DisposeAction(() =>
|
|
{
|
|
CurrentScope = parentScope;
|
|
});
|
|
}
|
|
}
|
|
}
|