【发布时间】:2013-08-03 18:01:37
【问题描述】:
我正在将应用程序从单租户转移到多租户。在此过程中,我将tenantId 添加到所有必需的模型中并更新了数据库(实体框架5)。
但是,我有所有需要更新的存储库。首先,不知道如何在Model Project中获取当前用户id(然后是tenantId)(不依赖WebSecurity,没有httpContext)。
其次,我不想在我的所有控制器中都编写这种丑陋/昂贵的代码。 (获取 UserId,调用数据库获取tenantId,然后将其传递给 Repository。)
public class PinTypeController : BaseController
{
private PinTypeRepository pinTypeRepo;
public PinTypeController()
{
UserRepository userRepo = new UserRepository();
UserProfile user = userRepo.GetById(WebSecurity.CurrentUserId);
this.pinTypeRepo = new PinTypeRepository(user.TenantId);
}
public ActionResult Index()
{
vmPinType vm = new vmPinType();
vm.NewPinType = new PinType();
vm.PinTypes = pinTypeRepo.GetAll();
return View(vm);
}
}
有没有更好的方法来存储tenantId,以便我可以从模型项目和我的所有存储库中访问它?
【问题讨论】:
标签: c# asp.net-mvc multi-tenant