Added Name to ICurrentTenant

pull/926/head
Halil ibrahim Kalkan 7 years ago
parent 7851020cf6
commit f0dd8cd1e8

@ -28,13 +28,13 @@ namespace Volo.Abp.AspNetCore.MultiTenancy
public async Task Invoke(HttpContext httpContext)
{
var tenant = await ResolveCurrentTenantAsync();
using (_currentTenant.Change(tenant?.Id))
using (_currentTenant.Change(tenant?.Id, tenant?.Name))
{
await _next(httpContext);
}
}
private async Task<TenantInfo> ResolveCurrentTenantAsync()
private async Task<TenantConfiguration> ResolveCurrentTenantAsync()
{
var tenantIdOrName = _tenantResolver.ResolveTenantIdOrName();
if (tenantIdOrName == null)
@ -51,7 +51,7 @@ namespace Volo.Abp.AspNetCore.MultiTenancy
return tenant;
}
private async Task<TenantInfo> FindTenantAsync(string tenantIdOrName)
private async Task<TenantConfiguration> FindTenantAsync(string tenantIdOrName)
{
if (Guid.TryParse(tenantIdOrName, out var parsedTenantId))
{

@ -43,7 +43,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Components.TenantSwitch
public class TenantSwitchViewModel
{
public TenantInfo Tenant { get; set; }
public TenantConfiguration Tenant { get; set; }
public ICurrentUser CurrentUser { get; set; }
}

@ -5,17 +5,17 @@ namespace Volo.Abp.MultiTenancy
{
public class AsyncLocalCurrentTenantIdAccessor : ICurrentTenantIdAccessor, ISingletonDependency
{
public TenantIdWrapper Current
public BasicTenantInfo Current
{
get => _currentScope.Value;
set => _currentScope.Value = value;
}
private readonly AsyncLocal<TenantIdWrapper> _currentScope;
private readonly AsyncLocal<BasicTenantInfo> _currentScope;
public AsyncLocalCurrentTenantIdAccessor()
{
_currentScope = new AsyncLocal<TenantIdWrapper>();
_currentScope = new AsyncLocal<BasicTenantInfo>();
}
}
}

@ -0,0 +1,27 @@
using System;
using JetBrains.Annotations;
namespace Volo.Abp.MultiTenancy
{
public class BasicTenantInfo
{
/// <summary>
/// Null indicates the host.
/// Not null value for a tenant.
/// </summary>
[CanBeNull]
public Guid? TenantId { get; }
/// <summary>
/// Name of the tenant if <see cref="TenantId"/> is not null.
/// </summary>
[CanBeNull]
public string Name { get; }
public BasicTenantInfo(Guid? tenantId, string name = null)
{
TenantId = tenantId;
Name = name;
}
}
}

@ -16,12 +16,12 @@ namespace Volo.Abp.MultiTenancy.ConfigurationStore
_options = options.Value;
}
public Task<TenantInfo> FindAsync(string name)
public Task<TenantConfiguration> FindAsync(string name)
{
return Task.FromResult(_options.Tenants?.FirstOrDefault(t => t.Name == name));
}
public Task<TenantInfo> FindAsync(Guid id)
public Task<TenantConfiguration> FindAsync(Guid id)
{
return Task.FromResult(_options.Tenants?.FirstOrDefault(t => t.Id == id));
}

@ -2,11 +2,11 @@
{
public class DefaultTenantStoreOptions
{
public TenantInfo[] Tenants { get; set; }
public TenantConfiguration[] Tenants { get; set; }
public DefaultTenantStoreOptions()
{
Tenants = new TenantInfo[0];
Tenants = new TenantConfiguration[0];
}
}
}

@ -9,6 +9,8 @@ namespace Volo.Abp.MultiTenancy
public virtual Guid? Id => _currentTenantIdAccessor.Current?.TenantId;
public string Name => _currentTenantIdAccessor.Current?.Name;
private readonly ICurrentTenantIdAccessor _currentTenantIdAccessor;
public CurrentTenant(ICurrentTenantIdAccessor currentTenantIdAccessor)
@ -16,15 +18,15 @@ namespace Volo.Abp.MultiTenancy
_currentTenantIdAccessor = currentTenantIdAccessor;
}
public IDisposable Change(Guid? id)
public IDisposable Change(Guid? id, string name = null)
{
return SetCurrent(id);
return SetCurrent(id, name);
}
private IDisposable SetCurrent(Guid? tenantId)
private IDisposable SetCurrent(Guid? tenantId, string name = null)
{
var parentScope = _currentTenantIdAccessor.Current;
_currentTenantIdAccessor.Current = new TenantIdWrapper(tenantId);
_currentTenantIdAccessor.Current = new BasicTenantInfo(tenantId, name);
return new DisposeAction(() =>
{
_currentTenantIdAccessor.Current = parentScope;

@ -10,6 +10,9 @@ namespace Volo.Abp.MultiTenancy
[CanBeNull]
Guid? Id { get; }
IDisposable Change(Guid? id);
[CanBeNull]
string Name { get; }
IDisposable Change(Guid? id, string name = null);
}
}

@ -8,6 +8,6 @@ namespace Volo.Abp.MultiTenancy
public interface ICurrentTenantIdAccessor
{
TenantIdWrapper Current { get; set; }
BasicTenantInfo Current { get; set; }
}
}

@ -5,8 +5,8 @@ namespace Volo.Abp.MultiTenancy
{
public interface ITenantStore
{
Task<TenantInfo> FindAsync(string name);
Task<TenantConfiguration> FindAsync(string name);
Task<TenantInfo> FindAsync(Guid id);
Task<TenantConfiguration> FindAsync(Guid id);
}
}

@ -5,7 +5,7 @@ using Volo.Abp.Data;
namespace Volo.Abp.MultiTenancy
{
[Serializable]
public class TenantInfo //TODO: Add a custom data to TenantInfo and make it available in ICurrentTenant
public class TenantConfiguration
{
public Guid Id { get; set; }
@ -13,12 +13,12 @@ namespace Volo.Abp.MultiTenancy
public ConnectionStrings ConnectionStrings { get; }
public TenantInfo()
public TenantConfiguration()
{
}
public TenantInfo(Guid id, [NotNull] string name)
public TenantConfiguration(Guid id, [NotNull] string name)
{
Check.NotNull(name, nameof(name));

@ -1,18 +0,0 @@
using System;
namespace Volo.Abp.MultiTenancy
{
public class TenantIdWrapper
{
/// <summary>
/// Null indicates the host.
/// Not null value for a tenant.
/// </summary>
public Guid? TenantId { get; }
public TenantIdWrapper(Guid? tenantId)
{
TenantId = tenantId;
}
}
}

@ -7,13 +7,13 @@ namespace Volo.Abp.MultiTenancy
public static class TenantStoreExtensions
{
[CanBeNull]
public static TenantInfo Find(this ITenantStore tenantStore, string name)
public static TenantConfiguration Find(this ITenantStore tenantStore, string name)
{
return AsyncHelper.RunSync(() => tenantStore.FindAsync(name));
}
[CanBeNull]
public static TenantInfo Find(this ITenantStore tenantStore, Guid id)
public static TenantConfiguration Find(this ITenantStore tenantStore, Guid id)
{
return AsyncHelper.RunSync(() => tenantStore.FindAsync(id));
}

@ -32,7 +32,7 @@ namespace Volo.Abp.AspNetCore.MultiTenancy
{
options.Tenants = new[]
{
new TenantInfo(_testTenantId, _testTenantName)
new TenantConfiguration(_testTenantId, _testTenantName)
};
});
});

@ -35,7 +35,7 @@ namespace Volo.Abp.Data.MultiTenancy
{
options.Tenants = new[]
{
new TenantInfo(_tenant1Id, "tenant1")
new TenantConfiguration(_tenant1Id, "tenant1")
{
ConnectionStrings =
{
@ -43,7 +43,7 @@ namespace Volo.Abp.Data.MultiTenancy
{"db1", "tenant1-db1-value"}
}
},
new TenantInfo(_tenant2Id, "tenant2")
new TenantConfiguration(_tenant2Id, "tenant2")
};
});
}

@ -32,8 +32,8 @@ namespace Volo.Abp.MultiTenancy
{
options.Tenants = new[]
{
new TenantInfo(_tenantAId, "A"),
new TenantInfo(_tenantAId, "B")
new TenantConfiguration(_tenantAId, "A"),
new TenantConfiguration(_tenantAId, "B")
};
});
}

Loading…
Cancel
Save