我想询问您对我处理多租户的方式的看法。我“米使用MVC3(切换到MVC4)和EF作为我的后端我使用一个单一的应用程序,共享模式多租户下面是代码:。在MVC上处理多租户
public abstract class Service<T> where T : Entity
{
private Repository<T> _repo;
public Service()
{
_repo = new Repository<T>();
}
public bool Authenticate(int id)
{
//var companyInfo = _authorizationRepository.GetApiKey(apiKey);
int tenantId = 0; // replaced by companyInfo using repository
var entity = _repo.GetQuery(tenantId).Where(e => e.Id == id).First();
if (tenantId != entity.TenantId)
throw new ArgumentException();
return true;
}
}
public class EmployeeService : Service<Employee>
{
private EmployeeRepository employeeRepository;
public EmployeeService()
{
employeeRepository = new EmployeeRepository();
}
public Employee GetEmployeeById(int employeeId)
{
this.Authenticate(employeeId);
return employeeRepository.GetById(employeeId);
}
}
public class Entity
{
public int Id { get; set; }
public int TenantId { get; set; }
}
当然DI会在那里,以及但是简单我在这里(暂时)删除了它们,我在服务层使用了泛型(对此感觉很脏),因为我在比较TenantId和将在类上传递的正确实体时遇到了困难。这个使用FilterAttributes,但我没有任何想法如何处理你的multitenancy问题?设计是否存在一些长期可能遇到的重要缺陷?如果你有一些使用FilterAttributes的示例,那将是一个很大的帮助。
Th anks!
为什么Multitenancy甚至是Web应用程序中的一个问题? – Tejs 2012-04-17 14:32:40
@Tejs对我来说关心的是我如何处理路由。基本上tenant1.domain.com和domain.com/tenant2都必须是有效的,并指向特定租户 – MikeSW 2012-04-17 14:47:17
这很酷,但该特定的URL方案与您决定使用的持久层无关。我想我想知道你的问题是什么。 – Tejs 2012-04-17 14:48:23