在哪里可以根据许可有条件地启用/禁用整个用户会话的过滤器的最佳地点?
例如,我只对管理员有" canseedeletedItems"权限,我想将其应用于所有内容,即,在此许可中来自用户的请求时,请禁用SoftDelete Filter。
。我首先想尝试将其包含在ModelBuilder中,但很快就意识到我无法从DAL访问服务层。
所以我的想法是在某种程度上向UOW的初始化器添加一些代码,但是我不确定如何做到这一点,我希望这是一种已经考虑的情况,但没有写入文档中。
我想做这样的事情:
if (IsGranted("PermissionName"))
CurrentUnitOfWorkProvider.Current.DisableFilter(AbpDataFilters.SoftDelete);`
对于基于用户的禁用过滤器,可以通过拦截器实现。因此,您需要做的是;为应用程序服务编写自定义拦截器。
此拦截器必须禁用/启用当前执行的过滤器
https://aspnetboilerplate.com/pages/documents/articles/aspect-oriented-programming-using-interpoctor-interceptors/index.html#articleateeinterpoctor
使用代码块中禁用ASPNET样板过滤器
using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
{
var people2 = _personRepository.GetAllList();
}
https://aspnetboilerplate.com/pages/documents/data-filters#disable-filters
禁用ASPNET样板过滤器全球
Configuration.UnitOfWork.OverrideFilter(AbpDataFilters.SoftDelete, false);
https://aspnetboilerplate.com/pages/documents/data-filters#disable-filters-globally