Open Closed

Possible to have DbMigrator updating permissions of exisiting tenants without adding reference Application.Contracts on Domain project? #1938


User avatar
0
christophe.baille created
  • ABP Framework version: v4.4.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

I previously made a feature to add all roles and permission when creating a new tenant which works perfectly. For that I created a class which inherit from IDataSeedContributor on Application project:

On SeedAsync method, I call this CreateRolesAndPermission which create roles, then for each role, I create permission

I get my roles from this class which in in Domain.Shared

To get the list of permission per role, I created an IEnumerable<string> that I create and fill directly on AppPermission class which is on Application.Contract project.

The feature which is not going well for me, is to update permissions when run DbMigrator.

Note/reminder about IDataSeedContributor (from some tests that I did): When creating a new tenant, it will run all classes which inherit from IDataSeedContributor from Application AND Domain projects. When run DbMigrator, it will run all classes which inherit from IDataSeedContributor from Domain projects only.

So, if I want to run something while running DbMigrator, I need to create a class which inherit from IDataSeedContributor on Domain project.

To update roles and pemission, I do something similar than for tenant creation, I get the list of roles from my class AppRoleConsts and check if exists or not on each tenant. To check all permission for each role, I then need to reach the list of permission, which is my issue : as I am now in Domain project, I do not have access to Application.Contract, and to keep a clean architecture, I should not add a reference. What I then tried, was to move my AppPermissions class from Application.Contract to Domain.Shared project. If most of it sounds ok, I got the issue when I want to add permissions from other AbPModule (here it is Blogging) to my IEnumerable<string>

The only way to make it work, it is to add the reference of Blogging.Application.Contracts.Shared to my domain project, which will make the architecture not clean again...

Is there any other way to make DbMigrator updating permission for each tenants without Domain project referencing Application.Contracts? It works on my project for now, but the architecture is a bit wrong now...

Would it not be possible to move all this permission from contract/contract.shared to domain.shared for example? It is just a suggestion/idea, I don't really know if this is wrong or not for your actual architecture actually...

Thanks


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    The only way to make it work, it is to add the reference of Blogging.Application.Contracts.Shared to my domain project, which will make the architecture not clean again...

    Hi

    Maybe you can reference of Blogging.Application.Contracts.Shared to DbMigrator. then move your IDataSeedContributor to DbMigrator project.

  • User Avatar
    0
    christophe.baille created

    I moved my IDataSeedContributor class to DbMigrator project and it's much better. Now I do not have to move my AppPermissions class from project Application.Contract to Domain.Shared anymore, so I do not have any issues about adding references as DbMigrator already reference Application.Contracts by default.

    I close the issue then, thanks for your help

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11