public ModController( ILogger <ModController> logger, TenantsDbContext tenantsDbContext, IConfiguration configuration) { _logger = logger; _tenantsDbContext = tenantsDbContext; _configuration = configuration; }
public static TenantsDbContext GetTenantContext() { var options = new DbContextOptionsBuilder <TenantsDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new TenantsDbContext(options); return(context); }
public DbTenantIdentificationService(TenantsDbContext context) { _tenants = new TenantMapping() { Default = "undefined" }; foreach (var t in context.Tenants) { _tenants.Tenants.Add(t.Key, t.Key); } }
public TenantServiceTests() { _context = Helpers.GetContext("test"); _tenantsDbContext = Helpers.GetTenantContext(); ITenantRepository tenantRepository = new EntityTenantRepository(_tenantsDbContext); IAsyncRepository <Setting> settingRepository = new EfRepository <Setting>(_context); ISettingService settingService = new SettingService(settingRepository); IAsyncRepository <ApplicationRole> roleRepository = new EfRepository <ApplicationRole>(_context); IRoleService roleService = new RoleService(roleRepository); _tenantService = new TenantService(tenantRepository, settingService, roleService); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TenantsDbContext tenantsDbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseDatabaseErrorPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseMultiTenancy(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { if (Configuration.GetValue <bool>("UsePathToResolveTenant")) { endpoints.MapControllerRoute( name: "default", pattern: "{tenant}/{controller=Home}/{action=Index}/{id?}"); } else { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); } endpoints.MapRazorPages(); }); tenantsDbContext.Database.Migrate(); SeedData.SeedTenants(GetConnectionStrings(), tenantsDbContext); CustomTenantsFileManager.AddAnyNewCustomDomainsOrIps(tenantsDbContext); }
static void Main(string[] args) { Console.WriteLine("Host for EF scripts"); string connectionString = "Server=(localdb)\\MSSQLLocalDB; Database=MicroFlow-X.Cli; Trusted_Connection=true; MultipleActiveResultSets=true;"; var optionsBuilder = new DbContextOptionsBuilder <TenantsDbContext>(); optionsBuilder.UseSqlServer(connectionString); Console.WriteLine("Creating database / applying migrations..."); using (var dbContext = new TenantsDbContext(optionsBuilder.Options)) { dbContext.Database.Migrate(); } Console.WriteLine("Done!"); }
/// <summary> /// Should be ran at startup /// </summary> /// <param name="tenantsDbContext"></param> public static void AddAnyNewCustomDomainsOrIps(TenantsDbContext tenantsDbContext) { if (tenantsDbContext == null) { return; } try { if (File.Exists(s_customTenantsFilePath)) { var tenants = tenantsDbContext.Tenants.ToList(); var customTenants = JsonConvert.DeserializeObject <List <Tenant> >(File.ReadAllText(s_customTenantsFilePath)); foreach (var customTenant in customTenants) { if (tenants.Any(tenant => tenant.Name == customTenant.Name && tenant.DomainNames != customTenant.DomainNames)) { var updatedTenant = tenants.SingleOrDefault(tenant => tenant.Name == customTenant.Name); updatedTenant.DomainNames = customTenant.DomainNames; tenantsDbContext.Update(updatedTenant); } if (tenants.Any(tenant => tenant.Name == customTenant.Name && tenant.IpAddresses != customTenant.IpAddresses)) { var updatedTenant = tenants.SingleOrDefault(tenant => tenant.Name == customTenant.Name); updatedTenant.IpAddresses = customTenant.IpAddresses; tenantsDbContext.Update(updatedTenant); } } tenantsDbContext.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public TenantsController(TenantsDbContext context) { this.context = context; }
private static DbContextOptions CreateDbContextOptions(IHttpContextAccessor httpContextAccessor, TenantsDbContext tenantsDbContext) { var tenantName = httpContextAccessor.HttpContext.GetTenant().Name; var connectionString = tenantsDbContext.Tenants.SingleOrDefault(tenant => tenant.Name == tenantName).ConnectionString; if (connectionString == null) { throw new NullReferenceException($"The connection string was null for the tenant: {tenantName}"); } var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>(); return(optionsBuilder.UseSqlServer(connectionString).Options); }
public ApplicationDbContext(IHttpContextAccessor httpContextAccessor, TenantsDbContext tenantsDbContext) : base(CreateDbContextOptions(httpContextAccessor, tenantsDbContext)) { }
public EntityPollRepository(ApplicationDbContext db, TenantsDbContext tenantsDb) { _db = db; _tenantsDb = tenantsDb; }
public EntityTenantRepository(TenantsDbContext db) { _db = db; }
/// <inheritdoc /> public TenantRepository(TenantsDbContext dbContext) : base(dbContext) { }
public TenantsDbStore(TenantsDbContext tenantsDbContext, IConfiguration configuration, ILogger <TenantsDbStore> logger) { _tenantsDbContext = tenantsDbContext; _configuration = configuration; _logger = logger; }