Multi-tenancy web application with filtered dbContext

前端 未结 2 1829
一向
一向 2020-12-28 23:47

I am new to ASP.Net MVC and multi-tenancy web application. I have done lots of reading, but being a beginner I just follow what I understand. So I managed to built a sample

2条回答
  •  失恋的感觉
    2020-12-29 00:01

    NInject DI can do the magic !! Provided you will have a login routine which creates the session variable "thisTenantID".

    In the Web Layer:

    private void AddBindings()
    {
        //Modified to inject session variable
        ninjectKernel.Bind().ToMethod(c => new EFDbContext((int)HttpContext.Current.Session["thisTenantID"]));
    
        ninjectKernel.Bind().To();
        ninjectKernel.Bind().To().WithConstructorArgument("tenantID", c => (int)HttpContext.Current.Session["thisTenantID"]);
    }
    

提交回复
热议问题