Exemplo n.º 1
0
 public TenantMiddleware(ITenantContextAccessor tenantContextAccessor, ITenantIdentificationService tenantIdentificationService, IOptions <TenancyHostingOptions> tenancyOptions, ITenantRepository tenantRepository)
 {
     _tenantContextAccessor       = tenantContextAccessor;
     _tenantIdentificationService = tenantIdentificationService;
     _tenancyOptions   = tenancyOptions;
     _tenantRepository = tenantRepository;
 }
Exemplo n.º 2
0
 public TenantService(
     IHttpContextAccessor accessor,
     ITenantIdentificationService <HttpContext> tenantIdentification)
 {
     _httpContext = accessor.HttpContext;
     _service     = tenantIdentification;
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public TenantService(IHttpContextAccessor accessor, ITenantIdentificationService service)
 {
     this._httpContext = accessor.HttpContext;
     this._service     = service;
 }
Exemplo n.º 5
0
 public MultiTenantService(IHttpContextAccessor accessor, ITenantsStore <TTenant> store, ITenantIdentificationService <TTenant> service)
 {
     _store  = store;
     _tenant = service.GetTenantAsync(accessor.HttpContext).Result;
 }
Exemplo n.º 6
0
 public MultiTenantService(IHttpContextAccessor accessor, ITenantsStore <TTenant> store, ITenantIdentificationService <TTenant> service, ITenantDbContextStrategyService strategyService)
     : this(accessor, store, service)
 {
     _strategyService = strategyService;
 }
Exemplo n.º 7
0
 public TenantService(IHttpContextAccessor accessor, ITenantIdentificationService service, IConfiguration configuration)
 {
     _httpContext   = accessor.HttpContext;
     _service       = service;
     _configuration = configuration;
 }
 private TenantIdentificationServiceTests WhenTenantIdentificationServiceIsInstantiated()
 {
     _service = new TenantIdentificationService(_configuration);
     return(this);
 }
Exemplo n.º 9
0
 public TenantService(ITenantIdentificationService service)
 {
     _service = service;
 }