Moved to multitenancy abstractions module.

pull/191/head
Halil İbrahim Kalkan 8 years ago
parent 4099af8cc1
commit 9e8a18ceae

@ -28,6 +28,7 @@ using Volo.Abp.Ui.Navigation;
using Volo.Abp.VirtualFileSystem;
using Volo.Abp.IdentityServer.Jwt;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.ConfigurationStore;
namespace AbpDesk.Web.Mvc
{
@ -72,11 +73,11 @@ namespace AbpDesk.Web.Mvc
{
options.Tenants = new[]
{
new Tenant(
new TenantInfo(
Guid.Parse("446a5211-3d72-4339-9adc-845151f8ada0"),
"acme"
),
new Tenant(
new TenantInfo(
Guid.Parse("25388015-ef1c-4355-9c18-f6b6ddbaf89d"),
"volosoft"
)

@ -1,15 +1,17 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace Volo.Abp.Data
{
[Serializable]
public class ConnectionStrings : Dictionary<string, string>
{
public const string DefaultConnectionStringName = "Default";
public string Default
{
get { return this.GetOrDefault(DefaultConnectionStringName); }
set { this[DefaultConnectionStringName] = value; }
get => this.GetOrDefault(DefaultConnectionStringName);
set => this[DefaultConnectionStringName] = value;
}
}
}

@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Data\Volo.Abp.Data.csproj" />
</ItemGroup>
</Project>

@ -1,8 +1,10 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
namespace Volo.Abp.MultiTenancy
{
[DependsOn(typeof(AbpDataModule))]
public class AbpMultiTenancyAbstractionsModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)

@ -19,7 +19,7 @@ namespace Volo.Abp.MultiTenancy
_currentScope = new AsyncLocal<TenantScope>();
}
public IDisposable EnterScope(Tenant tenant)
public IDisposable EnterScope(TenantInfo tenant)
{
var parentScope = CurrentScope;
CurrentScope = new TenantScope(tenant);

@ -3,7 +3,7 @@ using System.Linq;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.MultiTenancy
namespace Volo.Abp.MultiTenancy.ConfigurationStore
{
//TODO: Move to another package.
[Dependency(TryRegister = true)]
@ -16,12 +16,12 @@ namespace Volo.Abp.MultiTenancy
_options = options.Value;
}
public Tenant Find(string name)
public TenantInfo Find(string name)
{
return _options.Tenants.FirstOrDefault(t => t.Name == name);
}
public Tenant Find(Guid id)
public TenantInfo Find(Guid id)
{
return _options.Tenants.FirstOrDefault(t => t.Id == id);
}

@ -0,0 +1,12 @@
namespace Volo.Abp.MultiTenancy.ConfigurationStore
{
public class ConfigurationTenantStoreOptions
{
public TenantInfo[] Tenants { get; set; }
public ConfigurationTenantStoreOptions()
{
Tenants = new TenantInfo[0];
}
}
}

@ -6,7 +6,7 @@ namespace Volo.Abp.MultiTenancy
public interface IMultiTenancyManager
{
[CanBeNull]
Tenant CurrentTenant { get; }
TenantInfo CurrentTenant { get; }
IDisposable ChangeTenant(Guid? tenantId);

@ -11,6 +11,6 @@ namespace Volo.Abp.MultiTenancy
[CanBeNull]
TenantScope CurrentScope { get; }
IDisposable EnterScope([CanBeNull] Tenant tenant);
IDisposable EnterScope([CanBeNull] TenantInfo tenant);
}
}

@ -6,9 +6,9 @@ namespace Volo.Abp.MultiTenancy
public interface ITenantStore
{
[CanBeNull]
Tenant Find(string name);
TenantInfo Find(string name);
[CanBeNull]
Tenant Find(Guid id);
TenantInfo Find(Guid id);
}
}

@ -8,7 +8,7 @@ namespace Volo.Abp.MultiTenancy
public class MultiTenancyManager : IMultiTenancyManager, ITransientDependency
{
public Tenant CurrentTenant => GetCurrentTenant();
public TenantInfo CurrentTenant => GetCurrentTenant();
private readonly ITenantScopeProvider _tenantScopeProvider;
private readonly ITenantStore _tenantStore;
@ -59,7 +59,7 @@ namespace Volo.Abp.MultiTenancy
return _tenantScopeProvider.EnterScope(tenant);
}
protected virtual Tenant GetCurrentTenant()
protected virtual TenantInfo GetCurrentTenant()
{
if (_tenantScopeProvider.CurrentScope != null)
{
@ -71,7 +71,7 @@ namespace Volo.Abp.MultiTenancy
return ResolveTenant();
}
protected virtual Tenant ResolveTenant()
protected virtual TenantInfo ResolveTenant()
{
var tenantIdOrName = _tenantResolver.ResolveTenantIdOrName();
if (tenantIdOrName == null)
@ -79,7 +79,7 @@ namespace Volo.Abp.MultiTenancy
return null;
}
Tenant tenant;
TenantInfo tenant;
//Try to find by id
if (Guid.TryParse(tenantIdOrName, out var tenantId))

@ -31,12 +31,12 @@ namespace Volo.Abp.MultiTenancy
//Requesting default connection string
if (connectionStringName == null)
{
return tenant.FindDefaultConnectionString() ??
return tenant.ConnectionStrings.Default ??
Options.ConnectionStrings.Default;
}
//Requesting specific connection string
var connString = tenant.FindConnectionString(connectionStringName);
var connString = tenant.ConnectionStrings.GetOrDefault(connectionStringName);
if (connString != null)
{
return connString;
@ -53,7 +53,7 @@ namespace Volo.Abp.MultiTenancy
return connStringInOptions;
}
return tenant.FindDefaultConnectionString() ??
return tenant.ConnectionStrings.Default ??
Options.ConnectionStrings.Default;
}
}

@ -0,0 +1,31 @@
using System;
using JetBrains.Annotations;
using Volo.Abp.Data;
namespace Volo.Abp.MultiTenancy
{
[Serializable]
public class TenantInfo
{
public Guid Id { get; }
public string Name { get; }
public ConnectionStrings ConnectionStrings { get; }
private TenantInfo()
{
}
public TenantInfo(Guid id, [NotNull] string name)
{
Check.NotNull(name, nameof(name));
Id = id;
Name = name;
ConnectionStrings = new ConnectionStrings();
}
}
}

@ -9,9 +9,9 @@ namespace Volo.Abp.MultiTenancy
/// Not null value for a tenant.
/// </summary>
[CanBeNull]
public Tenant Tenant { get; }
public TenantInfo Tenant { get; }
public TenantScope([CanBeNull] Tenant tenant)
public TenantScope([CanBeNull] TenantInfo tenant)
{
Tenant = tenant;
}

@ -1,12 +0,0 @@
namespace Volo.Abp.MultiTenancy
{
public class ConfigurationTenantStoreOptions
{
public Tenant[] Tenants { get; set; }
public ConfigurationTenantStoreOptions()
{
Tenants = new Tenant[0];
}
}
}

@ -4,7 +4,7 @@ using Volo.Abp.Domain.Entities;
namespace Volo.Abp.MultiTenancy
{
public class TenantConnectionString : Entity
public class TenantConnectionString : Entity //TODO: This should be a value object!
{
public virtual Guid TenantId { get; protected set; }

@ -7,6 +7,7 @@ using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Shouldly;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.ConfigurationStore;
using Xunit;
namespace Volo.Abp.AspNetCore.MultiTenancy
@ -31,7 +32,7 @@ namespace Volo.Abp.AspNetCore.MultiTenancy
{
options.Tenants = new[]
{
new Tenant(_testTenantId, _testTenantName)
new TenantInfo(_testTenantId, _testTenantName)
};
});
});

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.ConfigurationStore;
using Xunit;
namespace Volo.Abp.Data.MultiTenancy
@ -30,18 +30,17 @@ namespace Volo.Abp.Data.MultiTenancy
services.Configure<ConfigurationTenantStoreOptions>(options =>
{
var tenant1Id = Guid.NewGuid();
options.Tenants = new[]
{
new Tenant(tenant1Id, "tenant1")
new TenantInfo(Guid.NewGuid(), "tenant1")
{
ConnectionStrings =
{
new TenantConnectionString(tenant1Id,ConnectionStrings.DefaultConnectionStringName, "tenant1-default-value"),
new TenantConnectionString(tenant1Id,"db1", "tenant1-db1-value")
}
{ ConnectionStrings.DefaultConnectionStringName, "tenant1-default-value"},
{"db1", "tenant1-db1-value"}
}
},
new Tenant(Guid.NewGuid(), "tenant2")
new TenantInfo(Guid.NewGuid(), "tenant2")
};
});
}

@ -1,6 +1,7 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.MultiTenancy.ConfigurationStore;
using Xunit;
namespace Volo.Abp.MultiTenancy
@ -32,8 +33,8 @@ namespace Volo.Abp.MultiTenancy
{
options.Tenants = new[]
{
new Tenant(Guid.NewGuid(), _tenantA),
new Tenant(Guid.NewGuid(), _tenantB)
new TenantInfo(Guid.NewGuid(), _tenantA),
new TenantInfo(Guid.NewGuid(), _tenantB)
};
});
}

Loading…
Cancel
Save