/// <summary> /// 初始化 <see cref="ObjectPool{T}"/> 类的新实例。 /// </summary> /// <param name="creator">创建对象的函数。</param> /// <param name="maxSize">最大对象数。</param> public ObjectPool(IServiceProvider serviceProvider, Func <T> creator, int maxSize = 100) { _creator = creator; _maxSize = maxSize; _serviceProvider = serviceProvider; _tenancyProvider = serviceProvider.TryGetService <ITenancyProvider <ObjectPoolTenancyInfo> >(); StartIdleCheckThread(); }
public async Task InvokeAsync( HttpContext httpContext, ITenancyContext <TTenant, TKey> tenancyContext, ITenancyProvider <TTenant, TKey> tenancyProvider, ITenantStore <TTenant, TKey> tenantStore) { var tenant = await tenancyProvider.GetCurrentTenantAsync(httpContext.RequestAborted).ConfigureAwait(false); if (_logger.IsEnabled(LogLevel.Information)) { if (tenant != null) { var tenantId = await tenantStore.GetTenantIdAsync(tenant, httpContext.RequestAborted).ConfigureAwait(false); var canonicalName = await tenantStore.GetCanonicalNameAsync(tenant, httpContext.RequestAborted).ConfigureAwait(false); _logger.LogInformation("Tenant {TenantId} with canonical name {CanonicalName} was found for request {RequestUrl}.", tenantId, canonicalName, httpContext.Request.GetDisplayUrl()); } else { _logger.LogInformation("No tenant was found for request {RequestUrl}.", httpContext.Request.GetDisplayUrl()); } } if (!httpContext.Items.ContainsKey(GlobalConst.HttpContextTenancyContext)) { tenancyContext.Tenant = tenant; httpContext.Items.Add(GlobalConst.HttpContextTenancyContext, tenancyContext); } else { httpContext.Items.TryGetValue(GlobalConst.HttpContextTenancyContext, out var currentTenancyContext); if (currentTenancyContext is ITenancyContext <TTenant, TKey> iTenancyContext) { iTenancyContext.Tenant = tenant; } } await _next(httpContext).ConfigureAwait(false); }
public async Task InvokeAsync(HttpContext httpContext, ITenancyContext <TTenant> tenancyContext, ITenancyProvider <TTenant> tenancyProvider, ITenantStore <TTenant> tenantStore) { var tenant = await tenancyProvider.GetCurrentTenantAsync(httpContext.RequestAborted).ConfigureAwait(false); if (_logger.IsEnabled(LogLevel.Information)) { if (tenant != null) { var tenantId = await tenantStore.GetTenantIdAsync(tenant, httpContext.RequestAborted).ConfigureAwait(false); var canonicalName = await tenantStore.GetCanonicalNameAsync(tenant, httpContext.RequestAborted).ConfigureAwait(false); _logger.LogInformation("Tenant {TenantId} with canonical name {CanonicalName} was found for request {RequestUrl}.", tenantId, canonicalName, httpContext.Request.GetDisplayUrl()); } else { _logger.LogInformation("No tenant was found for request {RequestUrl}.", httpContext.Request.GetDisplayUrl()); } } tenancyContext.Tenant = tenant; await _next(httpContext).ConfigureAwait(false); }