0
我正在使用Autofac作爲IoC容器和Autofac.Multitenant
包,用於多租戶。Autofac Multi-Tenant ASP.NET應用程序返回租戶而不是標識符
我有一個容器的設置是這樣的:
var builder = new ContainerBuilder();
// Register the controllers
builder.RegisterControllers(typeof(Deskful.Web.DeskfulApplication).Assembly);
// Tenant Identifier
var tenantIdentifier = new RequestSubdomainStrategy();
builder.RegisterInstance(tenantIdentifier).As<ITenantIdentificationStrategy>();
// Build container
var container = builder.Build();
// Tenant container
var mtc = new MultitenantContainer(tenantIdentifier, container);
// Set autofac as dependency resolver
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
我的標識策略:
public class RequestSubdomainStrategy : ITenantIdentificationStrategy
{
public bool TryIdentifyTenant(out object tenantId)
{
tenantId = null;
try
{
var context = HttpContext.Current;
if (context != null && context.Request != null)
{
var site = context.Request.Url.Host;
tenantId = 1;
}
}
catch { }
return tenantId != null;
}
}
然後在我的控制,我需要的房客,我可以做注射ITenantIdentificationStrategy
後如下:
var tenantId = this.TenantIdStrategy.IdentifyTenant<int>();
我的問題是,如何存儲租戶對象d通過我的身份識別過程,我可以訪問租戶的所有屬性?
因爲現在它只返回id。