Пример #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");
        }
        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)}"));
            }
        }
        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
 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;
 }