Open Closed

If we refer to other Application layer Contracts, lead to static access storage, additional load to other Application permissions, move XXXPermissionDefinitionProvider to Application layer #10228


User avatar
0
heshengli created
    Configure<PermissionManagementOptions>(options =>
    {

options.ISaveStaticPermissionsToDatabase= true; options.IsDynamicPermissionStoreEnabled = false; });


2 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution Given your configuration:
    • ISaveStaticPermissionsToDatabase = true: ABP will persist statically-defined permissions (from your PermissionDefinitionProvider classes) into the PermissionDefinition records on startup. This avoids runtime reflection lookups and enables querying/managing those definitions via the Permission Management module.
    • IsDynamicPermissionStoreEnabled = false: Disables custom/dynamic permission store providers. ABP will use the built‑in permission store (cached + DB-backed). This can reduce complexity and unexpected provider hits.

    Addressing your points:

    A) “If we refer to other Application layer Contracts, lead to static access storage”

    • Best practice: Place PermissionDefinitionProvider in the Application.Contracts layer of the module that owns those permissions. Other modules can reference the Contracts assembly to access the permission name constants without introducing runtime dependency cycles. This is the standard ABP approach and does not cause runtime permission “static access storage” risks by itself. It’s the recommended source of truth for permission names and localization.

    B) “Additional load to other Application permissions”

    • With ISaveStaticPermissionsToDatabase = true, permission definitions are saved once (on startup/first run), then served via cache and DB. Combined with IsDynamicPermissionStoreEnabled = false, ABP will not query additional dynamic providers. This typically reduces load, not increase it. For performance:
      • Ensure distributed cache (e.g., Redis) is properly configured in production.
      • Keep permission grouping/nesting balanced; a very large number of permissions can increase the first application-configuration call cost.
      • Avoid querying permission grants in your overridden AbpApplicationConfigurationAppService.GetAsync beyond what ABP already returns; if you must, cache your extra computations.

    C) “Move XXXPermissionDefinitionProvider to Application layer”

    • Correct location is Application.Contracts (not Application). ABP docs and samples define PermissionDefinitionProvider in the *.Application.Contracts project so UI/API layers and seed/migrator can reference it.
    • Seeders (e.g., DbMigrator) should reference Application.Contracts to access permission names and definitions when seeding role grants.

    D) Recommended setup

    • Keep PermissionDefinitionProvider in MyModule.Application.Contracts.
    • Keep your configuration as-is if you don’t need dynamic providers:
    Configure<PermissionManagementOptions>(options =>
      {
          options.ISaveStaticPermissionsToDatabase = true;
          options.IsDynamicPermissionStoreEnabled = false;
      });
    
    • If you seed role permissions, implement a data seed contributor that uses IPermissionManager / IPermissionDataSeeder or similar to grant permissions to roles/users at migration time. Ensure the DbMigrator references Application.Contracts so it sees the definitions.

    E) Troubleshooting tips

    • If the first /api/abp/application-configuration becomes heavy:
      • Remove custom extra DB scans from overridden GetAsync or wrap them with distributed cache keyed by user/tenant.
      • Rely on ABP’s built-in permission list in ApplicationConfigurationDto unless you must enrich; then precompute and cache module maps.
      • Verify Redis connection and ABP DistributedCache options (timeouts) to avoid slow cache misses.
    1. Sources
    • https://github.com/abpframework/abp (repository with PermissionManagement module and seed contributor patterns)
    • Permission seeding guidance referencing PermissionDataSeedContributor pattern: https://abp.io/support/questions/3174

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    你好

    这会有任何问题吗?

    谢谢

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on December 17, 2025, 07:08
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.