2

I'm trying to extend AbpUserRoles in order to add new column into it. I was able to do that as following:

public class MyUserRole : Abp.Authorization.Users.UserRole
{

    public int MyCustomColumn { get; set; }

    public MyUserRole() { }

    public MyUserRole(int tenantId, long userId, int roleId, int myCustomColumnId)
        :base(tenantId, userId, roleId)
    {
        this.MyCustomColumn = myCustomColumnId;
    }
}

After above code, I added and updated migrations, and MyCustomColumn appeared in database.

Questoin: But I'm not getting how to use it. I tried registering it in my WebModule as IRepository<MyUserRole> and tried injecting it in RoleManager, but it did not work. I'm banging my head with this since last day, and seems there's something obvious I'm missing. Or it is not even possible?

Zeeshan
  • 2,535
  • 1
  • 22
  • 43
  • this might help you https://aspnetzero.com/Documents/Extending-Existing-Entities – vivek nuna Oct 05 '18 at 09:32
  • 1
    What do you mean by not working? You don't need to register the IRepository interface manually. Abp will resolve the correct entity when you inject MyUserRole repository using proper DI method – ryan.c Oct 05 '18 at 17:30
  • @ryan.c by "not working", i mean that MyUserRole repository is not injected. What do you mean by "proper DI method"? Please clear with example in answer. – Zeeshan Oct 07 '18 at 12:06
  • Share you implementation of RoleManager and how you use it. – ryan.c Oct 07 '18 at 14:27
  • Did you add `DbSet`? – aaron Oct 08 '18 at 04:53
  • @aaron, I tried defining `IDbset` in MyDbContext class, but it did not help. – Zeeshan Dec 20 '18 at 07:02
  • @ryan.c, The problem is that soon as I override UserRole as shown in question (even column is added in db after applying migrations) the abp doesn't seem to be reading the permissions correctly. And on starting application, I start getting `AbpAuthorizationException: Required permissions are not granted...`. Please guide me on this. – Zeeshan Dec 20 '18 at 07:06
  • Create a repro project on GitHub. – aaron Dec 20 '18 at 10:25

0 Answers0