コード例 #1
0
 public TenantConnectionResolver(TenantSettings <TDbContext> setting, TenantInfo tenantInfo,
                                 TenantOption tenantOption, IServiceProvider serviceProvider)
 {
     this.tenantOption    = tenantOption;
     this.setting         = setting;
     this.tenantInfo      = tenantInfo;
     this.serviceProvider = serviceProvider;
 }
コード例 #2
0
        public string GetConnection(TenantOption option, TenantInfo tenantInfo)
        {
            var span = tenantInfo.Name.AsSpan();

            if (span.Length > 4 && int.TryParse(span.Slice(5, span.Length - 5).ToString(), out var number))
            {
                return(String.Format(dbcontainerFormat, number % containerCount));
            }
            throw new NotSupportedException("tenant invalid");
        }
コード例 #3
0
        public string GetConnection(TenantOption option, TenantInfo tenantInfo)
        {
            var span = tenantInfo.Name.AsSpan();

            if (span.Length > 4 && int.TryParse(span[5].ToString(), out var number))
            {
                return(configuration.GetConnectionString($"{option.ConnectionPrefix}container{number % 2 + 1}"));
            }
            throw new NotSupportedException("tenant invalid");
        }
コード例 #4
0
        public string GetConnection(TenantOption option, TenantInfo tenantInfo)
        {
            dynamic info = tenantInfo;

            if (info?.IsWrite == true)
            {
                return(configuration.GetConnectionString($"{option.ConnectionPrefix}write"));
            }
            else
            {
                var mod = random.Value.Next(1000) % 2;
                return(configuration.GetConnectionString($"{option.ConnectionPrefix}read{(mod + 1)}"));
            }
        }
コード例 #5
0
        public string GetConnection(TenantOption option, TenantInfo tenantInfo)
        {
            string connectionString = null;

            switch (option.ConnectionType)
            {
            case ConnectionResolverType.ByDatabase:
                connectionString = configuration.GetConnectionString($"{option.ConnectionPrefix}{tenantInfo.Name}");
                break;

            case ConnectionResolverType.ByTable:
            case ConnectionResolverType.BySchema:
                connectionString = configuration.GetConnectionString(option.ConnectionName);
                break;
            }

            return(connectionString);
        }
コード例 #6
0
ファイル: AppScoped.cs プロジェクト: jvbalcev/TinySaas
 public AppScoped(IOptions <AppOption> appOption, IOptions <TenantOption> tenantOption)
 {
     _appOption    = appOption.Value;
     _tenantOption = tenantOption.Value;
 }
コード例 #7
0
 public TenantEntityBuilder(IEntityScaner <TDbContext> entityScaner, TenantOption tenantOption, TenantInfo tenantInfo)
 {
     this.tenantInfo   = tenantInfo;
     this.tenantOption = tenantOption;
     this.entityScaner = entityScaner;
 }