[英]MVC Multitenant Application Instance Scope on Context using Autofac?
Hi everyone I am optimizing my Application and have a Question about it. 大家好,我正在优化我的应用程序,对此有疑问。 I have a Design that looks like this: 我有一个外观如下的设计:
ApplicationCore -> T4 from ApplicationDatabases Model Generator ApplicationDatabases Model Generator中的ApplicationCore-> T4
ApplicationData -> Respositories which Access the Database Context in ApplicationCore ApplicationData->在ApplicationCore中访问数据库上下文的存储库
public class entityRepository<TEntity> : entityRepository<TEntity> where TEntity : class, IEntity
{
protected readonly DatabaseContext dbContext;
protected readonly IDbSet<TEntity> currentTableContext;
public entityRepository(DatabaseContext context)
{
this.DbContext = context;
currentTableContext = context.Set<TEntity>();
}
ApplicationDatabases -> Database created from Model Generator ApplicationDatabases->从Model Generator创建的数据库
ApplicationServices -> Services that creates a entityRepository ApplicationServices->创建entityRepository的服务
private readonly entityRepository<Users> _userRepository;
public userService(entityRepository<Users> userRepository)
{
_userRepository = userRepository;
}
What I would like to know if I am allowed to Register the entityRepository as InstancePerTenant in Autofac or should I use another Instance Scope. 我想知道是否可以在Autofac中将entityRepository注册为InstancePerTenant,还是应该使用另一个Instance Scope?
builder.Register(context => new DatabaseContext()).InstancePerTenant();
builder.RegisterGeneric(typeof(entityRepository<>)).As(typeof(IentityRepository<>)).InstancePerTenant;
I am doing that at the moment and it works but I am not sure If I would get any Resources or similiar Problems later. 我目前正在这样做,并且可以正常工作,但是我不确定以后是否会遇到任何资源或类似问题。 I would also be happy if I get some suggestions. 如果我得到一些建议,我也会很高兴。
IMHO, I have worked in a project that is multi-tenant, but does not use autofac. 恕我直言,我曾在一个多租户的项目中工作,但不使用autofac。 I have few points to put forth to you for a discussion 我没有什么要讨论的。
Kindly think through these use cases and the others that might come up after moving to production and share your thoughts. 请仔细考虑这些用例,以及可能进入生产并分享您想法的其他用例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.