我已根据文档{@ {3}}
将Odata添加到我的asp.net核心样板项目中。如何在AbpODataEntityController中访问当前的TenantId和UserId?
答案 0 :(得分:0)
您可以检查此示例代码。
public class MyODataController : Abp.AspNetCore.OData.Controllers.AbpODataEntityController<User, long>, ITransientDependency
{
private readonly UserManager _userManager;
public MyODataController(IRepository<User, long> repository, UserManager userManager) : base(repository)
{
_userManager = userManager;
}
public long? GetCurrentUserId()
{
return _userManager.AbpSession.UserId;
}
public int? GetCurrentTenantId()
{
return _userManager.AbpSession.TenantId;
}
}
PS:别忘了继承自ITransientDependency,以便它注册到依赖项服务。