mirror of https://github.com/abpframework/abp.git
8 changed files with 75 additions and 60 deletions
@ -1,21 +0,0 @@ |
|||||
using System.Threading; |
|
||||
using Volo.DependencyInjection; |
|
||||
|
|
||||
namespace Volo.Abp.MultiTenancy |
|
||||
{ |
|
||||
public class AmbientTenantAccessor : IAmbientTenantAccessor, ISingletonDependency //TODO: Should be IScopedDependency?
|
|
||||
{ |
|
||||
public AmbientTenantInfo AmbientTenant |
|
||||
{ |
|
||||
get { return _tenant.Value; } |
|
||||
set { _tenant.Value = value; } |
|
||||
} |
|
||||
|
|
||||
private readonly AsyncLocal<AmbientTenantInfo> _tenant; |
|
||||
|
|
||||
public AmbientTenantAccessor() |
|
||||
{ |
|
||||
_tenant = new AsyncLocal<AmbientTenantInfo>(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,18 @@ |
|||||
|
using JetBrains.Annotations; |
||||
|
|
||||
|
namespace Volo.Abp.MultiTenancy |
||||
|
{ |
||||
|
public class AmbientTenantScope |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Null indicates the host.
|
||||
|
/// Not null value for a tenant.
|
||||
|
/// </summary>
|
||||
|
public TenantInfo Tenant { get; set; } |
||||
|
|
||||
|
public AmbientTenantScope([CanBeNull] TenantInfo tenant) |
||||
|
{ |
||||
|
Tenant = tenant; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using System.Threading; |
||||
|
using Volo.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.MultiTenancy |
||||
|
{ |
||||
|
public class AsyncLocalAmbientTenantScopeProvider : IAmbientTenantScopeProvider, IScopedDependency |
||||
|
{ |
||||
|
public AmbientTenantScope CurrentScope |
||||
|
{ |
||||
|
get { return _tenant.Value; } |
||||
|
set { _tenant.Value = value; } |
||||
|
} |
||||
|
|
||||
|
private readonly AsyncLocal<AmbientTenantScope> _tenant; |
||||
|
|
||||
|
public AsyncLocalAmbientTenantScopeProvider() |
||||
|
{ |
||||
|
_tenant = new AsyncLocal<AmbientTenantScope>(); |
||||
|
} |
||||
|
|
||||
|
public IDisposable CreateScope(TenantInfo tenantInfo) |
||||
|
{ |
||||
|
var parentScope = CurrentScope; |
||||
|
CurrentScope = new AmbientTenantScope(tenantInfo); |
||||
|
return new DisposeAction(() => |
||||
|
{ |
||||
|
CurrentScope = parentScope; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,22 +0,0 @@ |
|||||
using JetBrains.Annotations; |
|
||||
|
|
||||
namespace Volo.Abp.MultiTenancy |
|
||||
{ |
|
||||
public interface IAmbientTenantAccessor |
|
||||
{ |
|
||||
AmbientTenantInfo AmbientTenant { get; set; } |
|
||||
} |
|
||||
|
|
||||
public class AmbientTenantInfo |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Null for host.
|
|
||||
/// </summary>
|
|
||||
public TenantInfo Tenant { get; set; } |
|
||||
|
|
||||
public AmbientTenantInfo([CanBeNull] TenantInfo tenant) |
|
||||
{ |
|
||||
Tenant = tenant; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,11 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.MultiTenancy |
||||
|
{ |
||||
|
public interface IAmbientTenantScopeProvider |
||||
|
{ |
||||
|
AmbientTenantScope CurrentScope { get; set; } |
||||
|
|
||||
|
IDisposable CreateScope(TenantInfo tenantInfo); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue