简体   繁体   English

使用Autofac在上下文上的MVC多租户应用程序实例范围?

[英]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 我没有什么要讨论的。

  1. In case of a multi-tenant application and having the user and entity repositories loaded on memory for each tenant, seems like a bit of overhead 如果是多租户应用程序,并且为每个租户将用户和实体存储库加载到内存中,似乎有点开销
  2. In case of a use case wherein a tenant wishes to view his child tenant's data, how can this be achieved 如果租户希望查看其子租户的数据,该如何实现?
  3. When there is an application load of 50 tenant's what happens to the parallelism and responsiveness to the load from the application point of view. 当一个应用程序负载为50个租户时,从应用程序的角度来看,并行性和对负载的响应情况如何。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM