Exemplo n.º 1
0
        private DemoDbContext CreateDbContext(IServiceProvider options)
        {
            var connectionStringPlaceHolder = Configuration.GetConnectionString("Default");
            var httpContextAccessor         = options.GetRequiredService <IHttpContextAccessor>();
            var cid = httpContextAccessor?.HttpContext?.Request.Headers["tenantId"].First();

            if (string.IsNullOrEmpty(cid))
            {
                cid = "base";
            }

            var connectionString = connectionStringPlaceHolder.Replace("{cid}", cid);
            var builder          = new DbContextOptionsBuilder <DemoDbContext>();

            builder.UseSqlServer(connectionString);
            var dbContext = new DemoDbContext(builder.Options);

            dbContext.MigrationCustom(cid);
            return(dbContext);
        }