mirror of https://github.com/abpframework/abp.git
14 changed files with 153 additions and 9 deletions
@ -1,9 +1,13 @@ |
|||
using Volo.Abp.Modularity; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.Identity |
|||
{ |
|||
public class AbpIdentityDomainSharedModule : AbpModule |
|||
{ |
|||
|
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpIdentityDomainSharedModule>(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,20 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.MultiTenancy.Domain.Shared</AssemblyName> |
|||
<PackageId>Volo.Abp.MultiTenancy.Domain.Shared</PackageId> |
|||
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,13 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.MultiTenancy |
|||
{ |
|||
public class AbpMultiTenancyDomainSharedModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpMultiTenancyDomainSharedModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
namespace Volo.Abp.MultiTenancy |
|||
{ |
|||
public static class TenantConnectionStringConsts |
|||
{ |
|||
public const int MaxNameLength = 256; |
|||
|
|||
public const int MaxValueLength = 1024; |
|||
} |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
namespace Volo.Abp.MultiTenancy |
|||
{ |
|||
public static class TenantConsts |
|||
{ |
|||
public const int MaxNameLength = 64; |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.MultiTenancy.EntityFrameworkCore |
|||
{ |
|||
[DependsOn(typeof(AbpMultiTenancyDomainModule))] |
|||
[DependsOn(typeof(AbpEntityFrameworkCoreModule))] |
|||
public class AbpMultiTenancyEntityFrameworkCoreModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
services.AddAssemblyOf<AbpMultiTenancyEntityFrameworkCoreModule>(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Microsoft.EntityFrameworkCore.Design; |
|||
|
|||
namespace Volo.Abp.MultiTenancy.EntityFrameworkCore |
|||
{ |
|||
/* This class is needed for EF Core command line tooling */ |
|||
|
|||
public class MultiTenancyDbContextFactory : IDesignTimeDbContextFactory<MultiTenancyDbContext> |
|||
{ |
|||
public MultiTenancyDbContext CreateDbContext(string[] args) |
|||
{ |
|||
var builder = new DbContextOptionsBuilder<MultiTenancyDbContext>(); |
|||
builder.UseSqlServer("Server=localhost;Database=AbpDesk;Trusted_Connection=True;"); |
|||
return new MultiTenancyDbContext(builder.Options); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
using Microsoft.EntityFrameworkCore; |
|||
using Volo.Abp.EntityFrameworkCore; |
|||
|
|||
namespace Volo.Abp.MultiTenancy.EntityFrameworkCore |
|||
{ |
|||
public class MultiTenancyDbContext : AbpDbContext<MultiTenancyDbContext> |
|||
{ |
|||
public DbSet<Tenant> Tenants { get; set; } |
|||
|
|||
public DbSet<TenantConnectionString> TenantConnectionStrings { get; set; } |
|||
|
|||
public MultiTenancyDbContext(DbContextOptions<MultiTenancyDbContext> options) |
|||
: base(options) |
|||
{ |
|||
} |
|||
|
|||
protected override void OnModelCreating(ModelBuilder builder) |
|||
{ |
|||
base.OnModelCreating(builder); |
|||
|
|||
//TODO: Split configuration to dedicated classes (probably a resuable extension method)
|
|||
|
|||
builder.Entity<Tenant>(b => |
|||
{ |
|||
b.ToTable("MtTenants"); //TODO: Make all table and schema names changeable
|
|||
|
|||
b.Property(t => t.Name).IsRequired().HasMaxLength(TenantConsts.MaxNameLength); |
|||
|
|||
b.HasMany(u => u.ConnectionStrings).WithOne().HasForeignKey(uc => uc.TenantId).IsRequired(); |
|||
|
|||
b.HasIndex(u => u.Name); |
|||
}); |
|||
|
|||
builder.Entity<TenantConnectionString>(b => |
|||
{ |
|||
b.ToTable("MtTenantConnectionStrings"); |
|||
|
|||
b.Property(cs => cs.Name).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxNameLength); |
|||
b.Property(cs => cs.Value).IsRequired().HasMaxLength(TenantConnectionStringConsts.MaxValueLength); |
|||
|
|||
b.HasIndex(cs => cs.TenantId); |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue