question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

why UnitOfWorkManagger.Current is null sometimes in using DisableFilter method?

See original GitHub issue

I use this scenario in RoleManager class:

public class RoleManager : AbpRoleManager<Role, User>
  {
      private readonly IUnitOfWorkManager _unitOfWorkManager;
      private readonly ICacheManager _cacheManager;
      private readonly IPermissionManager _permissionManager;
      private readonly RoleStore _roleStore;

      public RoleManager(
          RoleStore store,
          IEnumerable<IRoleValidator<Role>> roleValidators,
          ILookupNormalizer keyNormalizer,
          IdentityErrorDescriber errors,
          ILogger<AbpRoleManager<Role, User>> logger,
          IPermissionManager permissionManager,
          ICacheManager cacheManager,
          IUnitOfWorkManager unitOfWorkManager,
          IRoleManagementConfig roleManagementConfig)
          : base(
              store,
              roleValidators,
              keyNormalizer,
              errors,
              logger,
              permissionManager,
              cacheManager,
              unitOfWorkManager,
              roleManagementConfig
          )
      {
          _cacheManager = cacheManager;
          _unitOfWorkManager = unitOfWorkManager;
          _permissionManager = permissionManager;
          _roleStore = store;
      }
  	
   public override async Task<bool> IsGrantedAsync(int roleId, Permission permission)
      {
          var cacheItem = await GetRolePermissionCacheItemAsync(roleId);
          return cacheItem.GrantedPermissions.Contains(permission.Name);
      }

      private async Task<RolePermissionCacheItem> GetRolePermissionCacheItemAsync(int roleId)
      {
          //take exception in current in belove code
          using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
          {
            
          }
      }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
acjhcommented, Jan 6, 2019

So this issue can be closed?

1reaction
acjhcommented, Jan 5, 2019

Because there is no unit of work.

You can make your method protected virtual and mark it as [UnitOfWork]:

[UnitOfWork]
protected virtual async Task<RolePermissionCacheItem> GetRolePermissionCacheItemAsync(int roleId)
{
    using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MayHaveTenant))
    {
        // ...
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Application.Current is null when calling from a unittest
I have a method that I'm trying to call from a unit test. This method will in real life be run from a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found