-3
With asp.net-core service injection
如何添加multi-tenant unitofwork
(包含多个存储库)?c#netcore 1.1 unitofwork multitenant
在我的代码现在,我有一个SetTenantId
功能,在每个存储库更新tenantId
:
public class ContinentsController : Controller, ICustomApiController<Continent>
{
private readonly IUnitOfWork _data;
public ContinentsController(IUnitOfWork unitOfWork)
{
_data = unitOfWork;
_data.SetTenantId(currentUserTenantId);
}
}
public interface IUnitOfWork : IDisposable
{
ITicketRepository Tickets { get; }
int Save();
void SetTenantId(int tenantId);
}
有没有其他的解决办法?
只要使用谷歌...所有你需要的是阅读的测试: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection –