コード例 #1
0
        /// <summary>
        /// Register a database that will hold data for multiple conjoined tenants
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="databaseIdentifier">A descriptive name for this database. If omitted, this will be derived from the connection string</param>
        /// <returns></returns>
        public IDatabaseExpression AddMultipleTenantDatabase(string connectionString, string databaseIdentifier = null)
        {
            var builder    = new NpgsqlConnectionStringBuilder(connectionString);
            var identifier = databaseIdentifier ?? $"{builder.Database}@{builder.Host}";

            var database = new MartenDatabase(Options, new ConnectionFactory(connectionString), identifier);

            _databases = _databases.AddOrUpdate(identifier, database);

            return(new DatabaseExpression(this, database));
        }
コード例 #2
0
        public void AddSingleTenantDatabase(string connectionString, string tenantId)
        {
            var database = new MartenDatabase(Options, new ConnectionFactory(connectionString), tenantId);

            _databases = _databases.AddOrUpdate(tenantId, database);

            var expression = new DatabaseExpression(this, database).ForTenants(tenantId);

            if (Default == null)
            {
                expression.AsDefault();
            }
        }
コード例 #3
0
 internal DatabaseExpression(StaticMultiTenancy parent, MartenDatabase database)
 {
     _parent   = parent;
     _database = database;
 }