public TenantMiddleware(ITenantContextAccessor tenantContextAccessor, ITenantIdentificationService tenantIdentificationService, IOptions <TenancyHostingOptions> tenancyOptions, ITenantRepository tenantRepository) { _tenantContextAccessor = tenantContextAccessor; _tenantIdentificationService = tenantIdentificationService; _tenancyOptions = tenancyOptions; _tenantRepository = tenantRepository; }
public TenantService( IHttpContextAccessor accessor, ITenantIdentificationService <HttpContext> tenantIdentification) { _httpContext = accessor.HttpContext; _service = tenantIdentification; }
public async Task Invoke(HttpContext context, ITenantIdentificationService tenantIdentificationService, ITenantContextAccessor tenantContextAccessor, ITenantRepository tenantRepository, IOptions <TenancyHostingOptions> tenancyOptions) { if (tenancyOptions.Value.TenancyType == TenancyType.None) { await _next(context); return; } if (tenantContextAccessor.TenantContext != null) { throw new ApplicationException("Tenant context is already set"); } var tenantId = await tenantIdentificationService.GetTenantIdAsync(); var tenant = await tenantRepository.Get(tenantId, context.RequestAborted) ?? throw new ApplicationException($"Tenant {tenantId} not found"); if (tenant.IsShared && tenancyOptions.Value.TenancyType == TenancyType.MonoTenant) { throw new ApplicationException( $"Received a message for shared tenant {tenantId} in a MonoTenant hosting"); } if (!tenant.IsShared && tenancyOptions.Value.TenancyType == TenancyType.MultiTenant) { throw new ApplicationException( $"Received a message for premium tenant {tenantId} in a MultiTenant (shared) context"); } if (tenancyOptions.Value.TenancyType == TenancyType.MonoTenant && tenancyOptions.Value.TenantId != tenantId) { throw new ApplicationException( $"Invalid tenant ID. Expected {tenancyOptions.Value.TenantId} but received {tenantId}"); } tenantContextAccessor.TenantContext = new TenantContext(tenant); await _next(context); }
public TenantService(IHttpContextAccessor accessor, ITenantIdentificationService service) { this._httpContext = accessor.HttpContext; this._service = service; }
public MultiTenantService(IHttpContextAccessor accessor, ITenantsStore <TTenant> store, ITenantIdentificationService <TTenant> service) { _store = store; _tenant = service.GetTenantAsync(accessor.HttpContext).Result; }
public MultiTenantService(IHttpContextAccessor accessor, ITenantsStore <TTenant> store, ITenantIdentificationService <TTenant> service, ITenantDbContextStrategyService strategyService) : this(accessor, store, service) { _strategyService = strategyService; }
public TenantService(IHttpContextAccessor accessor, ITenantIdentificationService service, IConfiguration configuration) { _httpContext = accessor.HttpContext; _service = service; _configuration = configuration; }
private TenantIdentificationServiceTests WhenTenantIdentificationServiceIsInstantiated() { _service = new TenantIdentificationService(_configuration); return(this); }
public TenantService(ITenantIdentificationService service) { _service = service; }