Browse Source

Merge branch 'dev' into resource-based-auth

pull/24184/head
Halil İbrahim Kalkan 2 months ago
parent
commit
d8be0a9a9a
  1. 6
      Directory.Packages.props
  2. 1
      README.md
  3. 2
      abp_io/AbpIoLocalization/AbpIoLocalization/Base/Localization/Resources/en.json
  4. BIN
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/cover.png
  5. 145
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/architecture-diagram.svg
  6. 82
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/automatic-caching-flow.svg
  7. 141
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/cache-invalidation-flow.svg
  8. 135
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/cache-scoping-diagram.svg
  9. 797
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/post.md
  10. 1
      docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/summary.md
  11. BIN
      docs/en/images/elsa-studio-wasm.png
  12. 97
      docs/en/modules/ai-management/index.md
  13. 85
      docs/en/modules/elsa-pro.md
  14. 3
      docs/en/modules/identity-pro.md
  15. 0
      docs/en/modules/identity/ldap.md
  16. 26
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/TelemetryService.cs
  17. 2
      framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo.Abp.EntityFrameworkCore.Oracle.csproj
  18. 6
      framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/AbpSqliteOptions.cs
  19. 39
      framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Interceptors/SqliteBusyTimeoutSaveChangesInterceptor.cs
  20. 22
      framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Sqlite/AbpEntityFrameworkCoreSqliteModule.cs
  21. 51
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContextOptions.cs
  22. 30
      framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs
  23. 18
      framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs
  24. 30
      framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolver.cs
  25. 1
      framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs
  26. 9
      latest-versions.json
  27. 5
      modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs
  28. 5
      modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs
  29. 5
      modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/EntityFrameworkCore/BlobStoringDatabaseEntityFrameworkCoreTestModule.cs
  30. 5
      modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs
  31. 1
      modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/CmsKitEntityFrameworkCoreTestModule.cs
  32. 5
      modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocsEntityFrameworkCoreTestModule.cs
  33. 5
      modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs
  34. 5
      modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs
  35. 5
      modules/openiddict/test/Volo.Abp.OpenIddict.EntityFrameworkCore.Tests/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictEntityFrameworkCoreTestModule.cs
  36. 2
      modules/permission-management/test/Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests/Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests.csproj
  37. 40
      modules/permission-management/test/Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests/Volo/Abp/PermissionManagement/EntityFrameworkCore/AbpPermissionManagementEntityFrameworkCoreTestModule.cs
  38. 1
      modules/setting-management/src/Volo.Abp.SettingManagement.Installer/AngularInstallationInfo.json
  39. 5
      modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementEntityFrameworkCoreTestModule.cs
  40. 5
      modules/tenant-management/test/Volo.Abp.TenantManagement.EntityFrameworkCore.Tests/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementEntityFrameworkCoreTestModule.cs
  41. BIN
      source-code/Volo.Abp.BasicTheme.SourceCode/Volo.Abp.BasicTheme.SourceCode.zip
  42. BIN
      source-code/Volo.ClientSimulation.SourceCode/Volo.ClientSimulation.SourceCode.zip

6
Directory.Packages.props

@ -7,7 +7,7 @@
<PackageVersion Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="4.0.0" />
<PackageVersion Include="aliyun-net-sdk-sts" Version="3.1.3" />
<PackageVersion Include="Aliyun.OSS.SDK.NetCore" Version="2.14.1" />
<PackageVersion Include="AsyncKeyedLock" Version="7.1.6" />
<PackageVersion Include="AsyncKeyedLock" Version="7.1.8" />
<PackageVersion Include="Autofac" Version="8.4.0" />
<PackageVersion Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Autofac.Extras.DynamicProxy" Version="7.1.0" />
@ -137,7 +137,7 @@
<PackageVersion Include="OpenIddict.Server.AspNetCore" Version="7.2.0" />
<PackageVersion Include="OpenIddict.Validation.AspNetCore" Version="7.2.0" />
<PackageVersion Include="OpenIddict.Validation.ServerIntegration" Version="7.2.0" />
<PackageVersion Include="Oracle.EntityFrameworkCore" Version="9.23.90" />
<PackageVersion Include="Oracle.EntityFrameworkCore" Version="10.23.26000" />
<PackageVersion Include="Polly" Version="8.6.3" />
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0" />
@ -196,4 +196,4 @@
<PackageVersion Include="Fody" Version="6.9.3" />
<PackageVersion Include="System.Management" Version="10.0.0" />
</ItemGroup>
</Project>
</Project>

1
README.md

@ -14,6 +14,7 @@
- [Quick Start](https://abp.io/docs/latest/tutorials/todo) is a single-part, quick-start tutorial to build a simple application with the ABP Framework. Start with this tutorial if you want to understand how ABP works quickly.
- [Web Application Development Tutorial](https://abp.io/docs/latest/tutorials/book-store) is a complete tutorial on developing a full-stack web application with all aspects of a real-life solution.
- [Modular Monolith Application](https://abp.io/docs/latest/tutorials/modular-crm/index): A multi-part tutorial that demonstrates how to create application modules, compose and communicate them to build a monolith modular web application.
- [Microservice Tutorial](https://abp.io/docs/latest/tutorials/microservice/index): A multi-part guide that walks you through building a microservice solution with ABP, from creating independent services and enabling inter-service communication to exposing them through an API Gateway and generating CRUD pages with ABP Suite.
## What ABP Provides?

2
abp_io/AbpIoLocalization/AbpIoLocalization/Base/Localization/Resources/en.json

@ -269,7 +269,7 @@
"Referral.CannotDeleteUsedLink": "You cannot delete a referral link that has already been used.",
"Referral.CannotReferYourself": "You cannot create a referral link for your own email address.",
"Referral:TargetEmail": "Target Email",
"Referral.CannotReferSameOrganizationMember": "You cannot create a referral link for a user who is already a member of your organization.",
"Referral.CannotReferSameOrganizationMember": "Referral links cannot be used for existing organization members.",
"LinkCopiedToClipboard": "Link copied to clipboard",
"AreYouSureToDeleteReferralLink": "Are you sure you want to delete this referral link?",
"DefaultErrorMessage": "An error occurred."

BIN
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/cover.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

145
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/architecture-diagram.svg

@ -0,0 +1,145 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 700">
<defs>
<style>
.box { fill: #f8f9fa; stroke: #1890ff; stroke-width: 2; }
.highlight-box { fill: #e6f7ff; stroke: #1890ff; stroke-width: 3; }
.service-box { fill: #fff7e6; stroke: #fa8c16; stroke-width: 2; }
.cache-box { fill: #f0f5ff; stroke: #597ef7; stroke-width: 2; }
.event-box { fill: #f6ffed; stroke: #52c41a; stroke-width: 2; }
.text { font-family: Arial, sans-serif; font-size: 14px; fill: #333; }
.title { font-family: Arial, sans-serif; font-size: 18px; fill: #1890ff; font-weight: bold; }
.section-title { font-family: Arial, sans-serif; font-size: 14px; fill: #1890ff; font-weight: bold; }
.small-text { font-family: Arial, sans-serif; font-size: 11px; fill: #666; }
.arrow { stroke: #666; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
.dashed { stroke-dasharray: 5, 5; }
</style>
<marker id="arrowhead" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#666" />
</marker>
</defs>
<!-- Title -->
<text class="title" x="500" y="35" text-anchor="middle">AutoCache Architecture</text>
<!-- Application Layer -->
<rect class="service-box" x="50" y="80" width="250" height="140" rx="5" />
<text class="section-title" x="175" y="105" text-anchor="middle">Application Service</text>
<rect class="box" x="70" y="120" width="210" height="40" rx="3" />
<text class="text" x="175" y="143" text-anchor="middle">BookAppService</text>
<text class="small-text" x="85" y="180" fill="#fa8c16">[Cache(typeof(Book))]</text>
<text class="small-text" x="85" y="195" fill="#666">public Task&lt;BookDto&gt; GetAsync()</text>
<!-- Interceptor Layer -->
<rect class="highlight-box" x="400" y="80" width="250" height="140" rx="5" />
<text class="section-title" x="525" y="105" text-anchor="middle">Cache Interceptor</text>
<rect class="box" x="420" y="120" width="210" height="40" rx="3" />
<text class="text" x="525" y="143" text-anchor="middle">AutoCacheInterceptor</text>
<text class="small-text" x="430" y="180">• Detect [Cache] attribute</text>
<text class="small-text" x="430" y="195">• Intercept method calls</text>
<!-- Cache Manager -->
<rect class="cache-box" x="750" y="80" width="200" height="140" rx="5" />
<text class="section-title" x="850" y="105" text-anchor="middle">Cache Manager</text>
<rect class="box" x="770" y="120" width="160" height="40" rx="3" />
<text class="text" x="850" y="143" text-anchor="middle">AutoCacheManager</text>
<text class="small-text" x="775" y="180">• Generate cache keys</text>
<text class="small-text" x="775" y="195">• Store/Retrieve data</text>
<!-- Arrows between layers -->
<path class="arrow" d="M 300 150 L 400 150" />
<path class="arrow" d="M 650 150 L 750 150" />
<!-- Distributed Cache -->
<rect class="cache-box" x="750" y="270" width="200" height="100" rx="5" />
<text class="section-title" x="850" y="295" text-anchor="middle">Distributed Cache</text>
<rect class="box" x="770" y="310" width="160" height="40" rx="3" />
<text class="text" x="850" y="333" text-anchor="middle">Redis / Memory</text>
<!-- Arrow to cache -->
<path class="arrow" d="M 850 220 L 850 270" />
<text class="small-text" x="860" y="250">Get/Set</text>
<!-- Entity Domain -->
<rect class="service-box" x="50" y="270" width="250" height="100" rx="5" />
<text class="section-title" x="175" y="295" text-anchor="middle">Domain Layer</text>
<rect class="box" x="70" y="310" width="210" height="40" rx="3" />
<text class="text" x="175" y="333" text-anchor="middle">Book Entity</text>
<!-- Event Bus -->
<rect class="event-box" x="400" y="270" width="250" height="100" rx="5" />
<text class="section-title" x="525" y="295" text-anchor="middle">Event Bus</text>
<rect class="box" x="420" y="310" width="210" height="40" rx="3" />
<text class="text" x="525" y="333" text-anchor="middle">EntityChangedEvent</text>
<!-- Invalidation Handler -->
<rect class="event-box" x="750" y="420" width="200" height="100" rx="5" />
<text class="section-title" x="850" y="445" text-anchor="middle">Invalidation Handler</text>
<rect class="box" x="770" y="460" width="160" height="40" rx="3" />
<text class="text" x="850" y="483" text-anchor="middle">Clear Related Caches</text>
<!-- Key Manager -->
<rect class="cache-box" x="400" y="420" width="250" height="100" rx="5" />
<text class="section-title" x="525" y="445" text-anchor="middle">Cache Key Manager</text>
<rect class="box" x="420" y="460" width="210" height="40" rx="3" />
<text class="text" x="525" y="483" text-anchor="middle">IAutoCacheKeyManager</text>
<!-- Event flow arrows -->
<path class="arrow" d="M 175 370 L 175 400 L 525 400 L 525 370" />
<text class="small-text" x="280" y="395">Publish</text>
<path class="arrow" d="M 525 370 L 525 420" />
<text class="small-text" x="535" y="400">Handle</text>
<path class="arrow" d="M 650 470 L 750 470" />
<text class="small-text" x="675" y="465">Invalidate</text>
<path class="arrow" d="M 850 420 L 850 370" />
<text class="small-text" x="860" y="400">Remove keys</text>
<!-- Scope information -->
<rect class="box" x="50" y="420" width="250" height="100" rx="5" />
<text class="section-title" x="175" y="445" text-anchor="middle">Cache Scopes</text>
<text class="small-text" x="65" y="470">• Global - Shared by all users</text>
<text class="small-text" x="65" y="487">• CurrentUser - Per user ID</text>
<text class="small-text" x="65" y="504">• AuthenticatedUser - Auth status</text>
<!-- Flow labels -->
<text class="small-text" x="50" y="570" fill="#1890ff" font-weight="bold">① Method Call</text>
<text class="small-text" x="50" y="590" fill="#666">Application service method is called</text>
<text class="small-text" x="270" y="570" fill="#1890ff" font-weight="bold">② Intercept</text>
<text class="small-text" x="270" y="590" fill="#666">Interceptor detects [Cache] attribute</text>
<text class="small-text" x="490" y="570" fill="#1890ff" font-weight="bold">③ Check Cache</text>
<text class="small-text" x="490" y="590" fill="#666">Manager checks distributed cache</text>
<text class="small-text" x="710" y="570" fill="#1890ff" font-weight="bold">④ Invalidate</text>
<text class="small-text" x="710" y="590" fill="#666">Entity changes clear related caches</text>
<!-- Legend -->
<line x1="50" y1="640" x2="950" y2="640" stroke="#ddd" stroke-width="1" />
<rect x="50" y="655" width="20" height="15" class="service-box" />
<text class="small-text" x="75" y="667">Application Layer</text>
<rect x="250" y="655" width="20" height="15" class="highlight-box" />
<text class="small-text" x="275" y="667">Cache Components</text>
<rect x="450" y="655" width="20" height="15" class="cache-box" />
<text class="small-text" x="475" y="667">Storage Layer</text>
<rect x="650" y="655" width="20" height="15" class="event-box" />
<text class="small-text" x="675" y="667">Event Handling</text>
</svg>

After

Width:  |  Height:  |  Size: 7.0 KiB

82
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/automatic-caching-flow.svg

@ -0,0 +1,82 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 400">
<defs>
<style>
.box { fill: #f8f9fa; stroke: #1890ff; stroke-width: 2; }
.highlight-box { fill: #e6f7ff; stroke: #1890ff; stroke-width: 2; }
.cache-box { fill: #f0f5ff; stroke: #597ef7; stroke-width: 2; }
.text { font-family: Arial, sans-serif; font-size: 14px; fill: #333; }
.title { font-family: Arial, sans-serif; font-size: 16px; fill: #1890ff; font-weight: bold; }
.small-text { font-family: Arial, sans-serif; font-size: 12px; fill: #666; }
.arrow { stroke: #666; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
.cache-arrow { stroke: #52c41a; stroke-width: 2; fill: none; marker-end: url(#arrowhead-green); }
.miss-arrow { stroke: #ff4d4f; stroke-width: 2; fill: none; marker-end: url(#arrowhead-red); }
</style>
<marker id="arrowhead" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#666" />
</marker>
<marker id="arrowhead-green" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#52c41a" />
</marker>
<marker id="arrowhead-red" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#ff4d4f" />
</marker>
</defs>
<!-- Title -->
<text class="title" x="450" y="30" text-anchor="middle">Automatic Caching Flow</text>
<!-- Client Call -->
<rect class="box" x="50" y="80" width="180" height="80" rx="5" />
<text class="text" x="140" y="115" text-anchor="middle">Client Call</text>
<text class="small-text" x="140" y="135" text-anchor="middle">GetAsync(bookId)</text>
<!-- Interceptor -->
<rect class="highlight-box" x="320" y="80" width="180" height="80" rx="5" />
<text class="text" x="410" y="110" text-anchor="middle">AutoCache</text>
<text class="text" x="410" y="130" text-anchor="middle">Interceptor</text>
<text class="small-text" x="410" y="145" text-anchor="middle">[Cache] detected</text>
<!-- Cache Check Diamond -->
<polygon class="cache-box" points="670,70 770,120 670,170 570,120" stroke="#1890ff" stroke-width="2" fill="#e6f7ff"/>
<text class="text" x="670" y="120" text-anchor="middle">Cache</text>
<text class="text" x="670" y="137" text-anchor="middle">Hit?</text>
<!-- Arrows -->
<path class="arrow" d="M 230 120 L 320 120" />
<path class="arrow" d="M 500 120 L 570 120" />
<!-- Cache Hit Path -->
<path class="cache-arrow" d="M 770 120 L 820 120 L 820 250 L 140 250 L 140 160" />
<text class="small-text" x="800" y="200" fill="#52c41a" font-weight="bold">✓ HIT</text>
<text class="small-text" x="780" y="265" fill="#52c41a">Return cached result (Fast!)</text>
<!-- Cache Miss Path -->
<path class="miss-arrow" d="M 670 170 L 670 240" />
<text class="small-text" x="685" y="210" fill="#ff4d4f" font-weight="bold">✗ MISS</text>
<!-- Execute Method -->
<rect class="box" x="580" y="260" width="180" height="80" rx="5" />
<text class="text" x="670" y="290" text-anchor="middle">Execute</text>
<text class="text" x="670" y="310" text-anchor="middle">Actual Method</text>
<text class="small-text" x="670" y="325" text-anchor="middle">Query Database</text>
<!-- Store in Cache -->
<rect class="cache-box" x="320" y="260" width="180" height="80" rx="5" />
<text class="text" x="410" y="290" text-anchor="middle">Store Result</text>
<text class="text" x="410" y="310" text-anchor="middle">in Cache</text>
<text class="small-text" x="410" y="325" text-anchor="middle">For future use</text>
<!-- Return to Client -->
<text class="small-text" x="270" y="285" text-anchor="middle">Return result</text>
<!-- Miss path arrows -->
<path class="arrow" d="M 580 300 L 500 300" />
<path class="arrow" d="M 320 300 L 230 300 L 230 120" />
<!-- Legend -->
<rect x="50" y="360" width="15" height="15" fill="#52c41a" opacity="0.3" />
<text class="small-text" x="70" y="372">Cache Hit (5-10ms)</text>
<rect x="250" y="360" width="15" height="15" fill="#ff4d4f" opacity="0.3" />
<text class="small-text" x="270" y="372">Cache Miss (100-500ms)</text>
</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

141
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/cache-invalidation-flow.svg

@ -0,0 +1,141 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 600">
<defs>
<style>
.box { fill: #f8f9fa; stroke: #1890ff; stroke-width: 2; }
.db-box { fill: #fff7e6; stroke: #fa8c16; stroke-width: 2; }
.cache-box { fill: #f0f5ff; stroke: #597ef7; stroke-width: 2; }
.event-box { fill: #f6ffed; stroke: #52c41a; stroke-width: 2; }
.invalidate-box { fill: #fff1f0; stroke: #ff4d4f; stroke-width: 2; }
.text { font-family: Arial, sans-serif; font-size: 14px; fill: #333; }
.title { font-family: Arial, sans-serif; font-size: 18px; fill: #1890ff; font-weight: bold; }
.section-title { font-family: Arial, sans-serif; font-size: 14px; fill: #1890ff; font-weight: bold; }
.small-text { font-family: Arial, sans-serif; font-size: 11px; fill: #666; }
.arrow { stroke: #666; stroke-width: 2; fill: none; marker-end: url(#arrowhead); }
.event-arrow { stroke: #52c41a; stroke-width: 2; fill: none; marker-end: url(#arrowhead-green); }
.invalidate-arrow { stroke: #ff4d4f; stroke-width: 3; fill: none; marker-end: url(#arrowhead-red); }
.step-number { fill: #1890ff; font-family: Arial, sans-serif; font-size: 16px; font-weight: bold; }
</style>
<marker id="arrowhead" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#666" />
</marker>
<marker id="arrowhead-green" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#52c41a" />
</marker>
<marker id="arrowhead-red" markerWidth="10" markerHeight="10" refX="9" refY="3" orient="auto">
<polygon points="0 0, 10 3, 0 6" fill="#ff4d4f" />
</marker>
</defs>
<!-- Title -->
<text class="title" x="500" y="35" text-anchor="middle">Cache Invalidation Workflow</text>
<!-- Step 1: User Action -->
<circle cx="100" cy="100" r="20" fill="#1890ff" />
<text class="step-number" x="100" y="107" text-anchor="middle" fill="white">1</text>
<rect class="box" x="150" y="70" width="180" height="60" rx="5" />
<text class="text" x="240" y="95" text-anchor="middle">User Action</text>
<text class="small-text" x="240" y="115" text-anchor="middle">UpdateAsync(bookId)</text>
<!-- Step 2: Database Update -->
<circle cx="100" cy="220" r="20" fill="#1890ff" />
<text class="step-number" x="100" y="227" text-anchor="middle" fill="white">2</text>
<rect class="db-box" x="150" y="190" width="180" height="60" rx="5" />
<text class="text" x="240" y="215" text-anchor="middle">Update Database</text>
<text class="small-text" x="240" y="235" text-anchor="middle">Repository.UpdateAsync()</text>
<!-- Step 3: Publish Event -->
<circle cx="100" cy="340" r="20" fill="#1890ff" />
<text class="step-number" x="100" y="347" text-anchor="middle" fill="white">3</text>
<rect class="event-box" x="150" y="310" width="180" height="60" rx="5" />
<text class="text" x="240" y="335" text-anchor="middle">Publish Event</text>
<text class="small-text" x="240" y="355" text-anchor="middle">EntityChangedEvent</text>
<!-- Arrows for steps 1-3 -->
<path class="arrow" d="M 240 130 L 240 190" />
<path class="arrow" d="M 240 250 L 240 310" />
<!-- Step 4: Event Handler -->
<circle cx="500" cy="340" r="20" fill="#1890ff" />
<text class="step-number" x="500" y="347" text-anchor="middle" fill="white">4</text>
<rect class="event-box" x="550" y="310" width="200" height="60" rx="5" />
<text class="text" x="650" y="330" text-anchor="middle">Invalidation</text>
<text class="text" x="650" y="348" text-anchor="middle">Handler</text>
<text class="small-text" x="650" y="363" text-anchor="middle">Listen for changes</text>
<!-- Arrow to handler -->
<path class="event-arrow" d="M 330 340 L 550 340" />
<text class="small-text" x="400" y="330" fill="#52c41a">Event Bus</text>
<!-- Step 5: UnitOfWork Check -->
<circle cx="500" cy="460" r="20" fill="#1890ff" />
<text class="step-number" x="500" y="467" text-anchor="middle" fill="white">5</text>
<rect class="box" x="550" y="430" width="200" height="60" rx="5" />
<text class="text" x="650" y="455" text-anchor="middle">Wait for UoW</text>
<text class="small-text" x="650" y="475" text-anchor="middle">OnCompleted() callback</text>
<!-- Arrow to UoW -->
<path class="arrow" d="M 650 370 L 650 430" />
<!-- Step 6: Clear Cache -->
<circle cx="850" cy="340" r="20" fill="#1890ff" />
<text class="step-number" x="850" y="347" text-anchor="middle" fill="white">6</text>
<rect class="invalidate-box" x="790" y="310" width="160" height="120" rx="5" />
<text class="text" x="870" y="335" text-anchor="middle">Clear Cache</text>
<!-- Cache entries being cleared -->
<line x1="805" y1="355" x2="935" y2="355" stroke="#ff4d4f" stroke-width="1" opacity="0.3"/>
<text class="small-text" x="815" y="375" fill="#ff4d4f">✗ GetAsync(id)</text>
<text class="small-text" x="815" y="392" fill="#ff4d4f">✗ GetListAsync()</text>
<text class="small-text" x="815" y="409" fill="#ff4d4f">✗ Related queries</text>
<!-- Arrow to clear cache -->
<path class="invalidate-arrow" d="M 750 460 L 870 460 L 870 430" />
<text class="small-text" x="785" y="452" fill="#ff4d4f" font-weight="bold">INVALIDATE</text>
<!-- Cache Storage Visualization -->
<rect class="cache-box" x="50" y="500" width="900" height="80" rx="5" />
<text class="section-title" x="500" y="525" text-anchor="middle">Redis / Distributed Cache</text>
<!-- Before invalidation -->
<text class="small-text" x="70" y="550" font-weight="bold">Before:</text>
<rect x="130" y="540" width="120" height="25" fill="#52c41a" opacity="0.3" rx="2" stroke="#52c41a"/>
<text class="small-text" x="190" y="557" text-anchor="middle">Book:Get:123 ✓</text>
<rect x="260" y="540" width="120" height="25" fill="#52c41a" opacity="0.3" rx="2" stroke="#52c41a"/>
<text class="small-text" x="320" y="557" text-anchor="middle">Book:List ✓</text>
<!-- After invalidation -->
<text class="small-text" x="560" y="550" font-weight="bold">After:</text>
<rect x="620" y="540" width="120" height="25" fill="#ff4d4f" opacity="0.2" rx="2" stroke="#ff4d4f" stroke-dasharray="3,3"/>
<text class="small-text" x="680" y="557" text-anchor="middle" fill="#999" text-decoration="line-through">Book:Get:123</text>
<rect x="750" y="540" width="120" height="25" fill="#ff4d4f" opacity="0.2" rx="2" stroke="#ff4d4f" stroke-dasharray="3,3"/>
<text class="small-text" x="810" y="557" text-anchor="middle" fill="#999" text-decoration="line-through">Book:List</text>
<!-- Arrow showing invalidation -->
<path class="invalidate-arrow" d="M 400 552 L 600 552" />
<text class="small-text" x="475" y="545" fill="#ff4d4f" font-weight="bold">CLEARED</text>
<!-- Timeline -->
<line x1="50" y1="100" x2="50" y2="490" stroke="#1890ff" stroke-width="2" opacity="0.3"/>
<text class="small-text" x="15" y="105" fill="#1890ff" transform="rotate(-90, 15, 105)">Timeline</text>
<!-- Info boxes -->
<rect x="400" y="70" width="250" height="100" rx="5" fill="#f0f5ff" stroke="#597ef7" stroke-width="2"/>
<text class="section-title" x="525" y="95" text-anchor="middle">Why Wait for UoW?</text>
<text class="small-text" x="415" y="115">• Ensures transaction completes</text>
<text class="small-text" x="415" y="132">• Prevents cache-DB inconsistency</text>
<text class="small-text" x="415" y="149">• Handles rollback scenarios</text>
<rect x="700" y="70" width="250" height="100" rx="5" fill="#fff1f0" stroke="#ff4d4f" stroke-width="2"/>
<text class="section-title" x="825" y="95" text-anchor="middle">Invalidation Scope</text>
<text class="small-text" x="715" y="115">• All caches with [Cache(Book)]</text>
<text class="small-text" x="715" y="132">• Across all scopes (Global, User)</text>
<text class="small-text" x="715" y="149">• Entity-specific keys by ID</text>
</svg>

After

Width:  |  Height:  |  Size: 7.8 KiB

135
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/images/cache-scoping-diagram.svg

@ -0,0 +1,135 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 500">
<defs>
<style>
.scope-box { fill: #f8f9fa; stroke: #1890ff; stroke-width: 2; }
.global-box { fill: #fff7e6; stroke: #fa8c16; stroke-width: 2; }
.user-box { fill: #e6f7ff; stroke: #1890ff; stroke-width: 2; }
.auth-box { fill: #f6ffed; stroke: #52c41a; stroke-width: 2; }
.entity-box { fill: #f9f0ff; stroke: #722ed1; stroke-width: 2; }
.text { font-family: Arial, sans-serif; font-size: 14px; fill: #333; }
.title { font-family: Arial, sans-serif; font-size: 18px; fill: #1890ff; font-weight: bold; }
.section-title { font-family: Arial, sans-serif; font-size: 15px; fill: #1890ff; font-weight: bold; }
.small-text { font-family: Arial, sans-serif; font-size: 11px; fill: #666; }
.code-text { font-family: 'Courier New', monospace; font-size: 11px; fill: #333; }
.badge { font-family: Arial, sans-serif; font-size: 10px; fill: white; font-weight: bold; }
</style>
</defs>
<!-- Title -->
<text class="title" x="500" y="35" text-anchor="middle">Cache Scoping Strategies</text>
<!-- Global Scope -->
<rect class="global-box" x="50" y="70" width="200" height="180" rx="5" />
<text class="section-title" x="150" y="95" text-anchor="middle">Global</text>
<circle cx="150" cy="130" r="30" fill="#fa8c16" opacity="0.2" stroke="#fa8c16" stroke-width="2"/>
<text class="text" x="150" y="137" text-anchor="middle" font-size="24">🌍</text>
<text class="small-text" x="65" y="175">Shared by all users</text>
<text class="small-text" x="65" y="190">Ideal for public data</text>
<rect x="65" y="200" width="170" height="35" fill="#fff" opacity="0.7" rx="3"/>
<text class="code-text" x="75" y="215">[Cache(typeof(Book),</text>
<text class="code-text" x="75" y="228">Scope = Global)]</text>
<!-- Current User Scope -->
<rect class="user-box" x="280" y="70" width="200" height="180" rx="5" />
<text class="section-title" x="380" y="95" text-anchor="middle">CurrentUser</text>
<circle cx="350" cy="130" r="25" fill="#1890ff" opacity="0.3" stroke="#1890ff" stroke-width="2"/>
<text class="text" x="350" y="137" text-anchor="middle" font-size="20">👤</text>
<circle cx="410" cy="130" r="25" fill="#1890ff" opacity="0.3" stroke="#1890ff" stroke-width="2"/>
<text class="text" x="410" y="137" text-anchor="middle" font-size="20">👤</text>
<text class="small-text" x="295" y="175">Per user (by ID)</text>
<text class="small-text" x="295" y="190">User-specific data</text>
<rect x="295" y="200" width="170" height="35" fill="#fff" opacity="0.7" rx="3"/>
<text class="code-text" x="305" y="215">[Cache(typeof(Order),</text>
<text class="code-text" x="305" y="228">Scope = CurrentUser)]</text>
<!-- Authenticated User Scope -->
<rect class="auth-box" x="510" y="70" width="200" height="180" rx="5" />
<text class="section-title" x="610" y="95" text-anchor="middle">AuthenticatedUser</text>
<rect x="565" y="110" width="90" height="40" fill="#52c41a" opacity="0.2" rx="3" stroke="#52c41a" stroke-width="2"/>
<text class="text" x="610" y="133" text-anchor="middle" font-size="16">🔐 Auth</text>
<rect x="565" y="155" width="90" height="30" fill="#ddd" opacity="0.4" rx="3" stroke="#999" stroke-width="1"/>
<text class="text" x="610" y="173" text-anchor="middle" font-size="12">Anonymous</text>
<text class="small-text" x="525" y="200">Auth vs Anonymous</text>
<rect x="525" y="210" width="170" height="35" fill="#fff" opacity="0.7" rx="3"/>
<text class="code-text" x="535" y="225">Scope =</text>
<text class="code-text" x="535" y="238">AuthenticatedUser</text>
<!-- Entity Scope -->
<rect class="entity-box" x="740" y="70" width="200" height="180" rx="5" />
<text class="section-title" x="840" y="95" text-anchor="middle">Entity</text>
<rect x="775" y="115" width="50" height="35" fill="#722ed1" opacity="0.2" rx="3" stroke="#722ed1" stroke-width="1"/>
<text class="text" x="800" y="135" text-anchor="middle" font-size="11">ID: 1</text>
<rect x="835" y="115" width="50" height="35" fill="#722ed1" opacity="0.2" rx="3" stroke="#722ed1" stroke-width="1"/>
<text class="text" x="860" y="135" text-anchor="middle" font-size="11">ID: 2</text>
<rect x="895" y="115" width="50" height="35" fill="#722ed1" opacity="0.2" rx="3" stroke="#722ed1" stroke-width="1"/>
<text class="text" x="920" y="135" text-anchor="middle" font-size="11">ID: 3</text>
<text class="small-text" x="755" y="170">Per entity instance</text>
<text class="small-text" x="755" y="185">By primary key</text>
<rect x="755" y="200" width="170" height="35" fill="#fff" opacity="0.7" rx="3"/>
<text class="code-text" x="765" y="215">[Cache(typeof(Book),</text>
<text class="code-text" x="765" y="228">Scope = Entity)]</text>
<!-- Examples Section -->
<line x1="50" y1="280" x2="950" y2="280" stroke="#ddd" stroke-width="2" />
<text class="section-title" x="50" y="310" fill="#1890ff">Common Use Cases</text>
<!-- Global Example -->
<rect class="global-box" x="50" y="325" width="220" height="70" rx="3" />
<text class="small-text" x="60" y="343" font-weight="bold" fill="#fa8c16">Global Scope</text>
<text class="small-text" x="60" y="360">✓ Product catalog</text>
<text class="small-text" x="60" y="375">✓ Configuration settings</text>
<text class="small-text" x="60" y="390">✓ Public announcements</text>
<!-- CurrentUser Example -->
<rect class="user-box" x="290" y="325" width="220" height="70" rx="3" />
<text class="small-text" x="300" y="343" font-weight="bold" fill="#1890ff">CurrentUser Scope</text>
<text class="small-text" x="300" y="360">✓ User profile</text>
<text class="small-text" x="300" y="375">✓ Shopping cart</text>
<text class="small-text" x="300" y="390">✓ User's order history</text>
<!-- AuthenticatedUser Example -->
<rect class="auth-box" x="530" y="325" width="200" height="70" rx="3" />
<text class="small-text" x="540" y="343" font-weight="bold" fill="#52c41a">Auth Scope</text>
<text class="small-text" x="540" y="360">✓ Member-only content</text>
<text class="small-text" x="540" y="375">✓ Navigation menus</text>
<text class="small-text" x="540" y="390">✓ Feature availability</text>
<!-- Entity Example -->
<rect class="entity-box" x="750" y="325" width="200" height="70" rx="3" />
<text class="small-text" x="760" y="343" font-weight="bold" fill="#722ed1">Entity Scope</text>
<text class="small-text" x="760" y="360">✓ Book details by ID</text>
<text class="small-text" x="760" y="375">✓ Product info by SKU</text>
<text class="small-text" x="760" y="390">✓ Invoice by number</text>
<!-- Cache Key Examples -->
<text class="section-title" x="50" y="435" fill="#1890ff">Cache Key Structure</text>
<rect x="50" y="445" width="900" height="40" fill="#f5f5f5" rx="3" stroke="#ddd" stroke-width="1"/>
<text class="code-text" x="60" y="462" fill="#fa8c16" font-weight="bold">Global:</text>
<text class="code-text" x="135" y="462">BookService:GetList:page1:size10</text>
<text class="code-text" x="60" y="477" fill="#1890ff" font-weight="bold">CurrentUser:</text>
<text class="code-text" x="135" y="477">OrderService:GetMyOrders:user:12345</text>
<text class="code-text" x="520" y="462" fill="#52c41a" font-weight="bold">Auth:</text>
<text class="code-text" x="570" y="462">MenuService:GetNav:auth:true</text>
<text class="code-text" x="520" y="477" fill="#722ed1" font-weight="bold">Entity:</text>
<text class="code-text" x="570" y="477">BookService:Get:entity:book-guid-123</text>
</svg>

After

Width:  |  Height:  |  Size: 7.5 KiB

797
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/post.md

@ -0,0 +1,797 @@
# Implement Automatic Method-Level Caching in ABP Framework
Caching is one of the most effective ways to improve application performance, but implementing it manually for every method can be tedious and error-prone. What if you could cache method results automatically with just an attribute? In this article, we'll explore how to build an automatic method-level caching system in ABP Framework that handles cache invalidation, supports multiple scopes, and integrates seamlessly with your existing application.
By the end of this guide, you'll understand how to implement attribute-based caching that automatically invalidates when entities change, supports user-specific and global caching scopes, and provides built-in metrics for monitoring cache performance.
> 💡 **Complete Implementation Available**: This article is based on a working demo project. You can find the complete implementation in the [AbpAutoCacheDemo repository](https://github.com/salihozkara/AbpAutoCacheDemo), with the core AutoCache library implementation available in [this commit](https://github.com/salihozkara/AbpAutoCacheDemo/commit/946df1fc07de6eddd26eb14013a09968cd59329b).
## What is Automatic Method-Level Caching?
Automatic method-level caching is a technique that intercepts method calls and caches their results without requiring manual cache management code. Instead of writing cache logic in every method, you simply decorate methods with attributes that define caching behavior.
![Automatic Caching Flow](./images/automatic-caching-flow.svg)
The key benefits include:
- **Reduced Boilerplate:** No repetitive cache management code in your business logic
- **Consistent Caching Strategy:** Centralized cache configuration and behavior
- **Smart Invalidation:** Automatic cache clearing when related entities change
- **Multiple Scopes:** Support for global, user-specific, and entity-specific caching
- **Built-in Monitoring:** Track cache hits, misses, and performance metrics
## Architecture Overview
The automatic caching system consists of several key components working together:
![Architecture Diagram](./images/architecture-diagram.svg)
**Core Components:**
1. **CacheAttribute:** The attribute you apply to methods to enable automatic caching
2. **AutoCacheInterceptor:** Intercepts method calls and handles cache operations
3. **AutoCacheManager:** Manages cache storage, retrieval, and key generation
4. **IAutoCacheKeyManager:** Handles cache key mapping and invalidation
5. **AutoCacheInvalidationHandler:** Listens to entity changes and clears related caches
This architecture leverages ABP's dynamic proxy system and event bus to provide seamless caching without modifying your business logic.
## Prerequisites
Before implementing automatic caching, ensure you have:
- ABP Framework 10.0 or later
## Implementation
> 📦 **Repository Structure**: The complete implementation is available in the [AbpAutoCacheDemo repository](https://github.com/salihozkara/AbpAutoCacheDemo). The AutoCache library is located in the `src/AutoCache` folder, making it easy to extract and reuse in your own projects.
### Step - 1: Create the AutoCache Module
First, let's create a separate module for our caching infrastructure. This makes it reusable across projects.
### Step - 1: Create the AutoCache Module
First, let's create a separate module for our caching infrastructure. This makes it reusable across projects.
Create `AutoCache.csproj`:
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Caching.StackExchangeRedis" Version="10.0.0" />
<PackageReference Include="Volo.Abp.Core" Version="10.0.0" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="10.0.0" />
</ItemGroup>
</Project>
```
Create the module class `AutoCacheModule.cs`:
```csharp
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Caching.StackExchangeRedis;
using Volo.Abp.Domain;
using Volo.Abp.Modularity;
namespace AutoCache;
[DependsOn(typeof(AbpDddDomainModule), typeof(AbpCachingStackExchangeRedisModule))]
public class AutoCacheModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.OnRegistered(AutoCacheRegister.RegisterInterceptorIfNeeded); // 👈 Register interceptor
}
}
```
This module automatically registers the cache interceptor for any class that uses the `CacheAttribute`.
### Step - 2: Define the Cache Attribute
The `CacheAttribute` is the core of our automatic caching system. It specifies which entities affect the cache and what scope to use.
Create `CacheAttribute.cs`:
```csharp
using System;
using Volo.Abp.Domain.Entities;
namespace AutoCache;
[AttributeUsage(AttributeTargets.Method)]
public class CacheAttribute : Attribute
{
/// <summary>
/// Entity types that affect this cache. When these entities change, the cache will be invalidated.
/// </summary>
public Type[] InvalidateOnEntities { get; set; }
/// <summary>
/// Scope of the cache (Global, CurrentUser, AuthenticatedUser, or Entity)
/// </summary>
public AutoCacheScope Scope { get; set; } = AutoCacheScope.Global;
/// <summary>
/// Absolute expiration time relative to now in milliseconds (0 = use default, -1 = disabled)
/// </summary>
public long AbsoluteExpirationRelativeToNow { get; set; }
/// <summary>
/// Sliding expiration time in milliseconds (0 = use default, -1 = disabled)
/// </summary>
public long SlidingExpiration { get; set; }
public bool ConsiderUow { get; set; }
public string AdditionalCacheKey { get; set; }
public CacheAttribute(params Type[] invalidateOnEntities) // 👈 Specify entities that trigger cache invalidation
{
foreach (var entityType in invalidateOnEntities)
{
ArgumentNullException.ThrowIfNull(entityType);
if (!typeof(IEntity).IsAssignableFrom(entityType))
{
throw new ArgumentException($"Type {entityType.FullName} must implement IEntity interface.");
}
}
InvalidateOnEntities = invalidateOnEntities;
}
}
```
**Key Properties:**
- **InvalidateOnEntities:** Array of entity types that, when modified, will clear this cache
- **Scope:** Determines cache visibility (Global, CurrentUser, AuthenticatedUser, Entity)
- **AbsoluteExpirationRelativeToNow / SlidingExpiration:** Control cache lifetime
### Step - 3: Define Cache Scopes
Cache scopes determine how cache entries are partitioned. Create `AutoCacheScope.cs`:
```csharp
using System;
namespace AutoCache;
[Flags]
public enum AutoCacheScope
{
/// <summary>
/// Cache is shared globally across all users
/// </summary>
Global,
/// <summary>
/// Cache is scoped to the current user (based on user ID)
/// </summary>
CurrentUser,
/// <summary>
/// Cache is scoped to authenticated vs unauthenticated users
/// </summary>
AuthenticatedUser,
/// <summary>
/// Cache is scoped to the primary key of the entity involved
/// </summary>
Entity
}
```
![Cache Scoping Strategy](./images/cache-scoping-diagram.svg)
**When to Use Each Scope:**
- **Global:** For data that's the same for all users (e.g., configuration, public lists)
- **CurrentUser:** For user-specific data (e.g., user profile, user's orders)
- **AuthenticatedUser:** For data that differs between authenticated and anonymous users
- **Entity:** For data tied to a specific entity instance (e.g., book details by ID)
### Step - 4: Implement the Cache Interceptor
The interceptor is the heart of automatic caching. It intercepts method calls, checks the cache, and stores results. Create `AutoCacheInterceptor.cs`:
```csharp
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
namespace AutoCache;
public class AutoCacheInterceptor : AbpInterceptor, ITransientDependency
{
private readonly ILogger<AutoCacheInterceptor> _logger;
private readonly AutoCacheOptions _options;
private static readonly MethodInfo GetOrAddCacheAsyncMethod;
private readonly AutoCacheManager _autoCacheManager;
private static readonly ConcurrentDictionary<Type, MethodInfo> MethodCache = new();
static AutoCacheInterceptor()
{
GetOrAddCacheAsyncMethod = typeof(AutoCacheInterceptor).GetMethod(
nameof(GetOrAddCacheAsync),
BindingFlags.NonPublic | BindingFlags.Instance
)!;
}
public AutoCacheInterceptor(
ILogger<AutoCacheInterceptor> logger,
IOptions<AutoCacheOptions> options,
AutoCacheManager autoCacheManager)
{
_logger = logger;
_autoCacheManager = autoCacheManager;
_options = options.Value;
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
// Check if caching is enabled and method has [Cache] attribute
if(!_options.Enabled ||
invocation.Method.GetCustomAttributes(typeof(CacheAttribute), true).FirstOrDefault()
is not CacheAttribute attribute)
{
await invocation.ProceedAsync(); // 👈 No caching, proceed normally
return;
}
var proceeded = false;
try
{
// Create generic method based on return type
var genericMethod = MethodCache.GetOrAdd(invocation.Method.ReturnType, t =>
{
var isGenericTask = t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Task<>);
var resultType = isGenericTask ? t.GetGenericArguments()[0] : t;
return GetOrAddCacheAsyncMethod.MakeGenericMethod(resultType);
});
// Execute cache logic
(var result, proceeded) = await (Task<(object, bool)>)genericMethod.Invoke(this, [invocation, attribute])!;
invocation.ReturnValue = result; // 👈 Set cached or fresh result
}
catch (Exception e)
{
_logger.LogError(e, "Error occurred while caching method {MethodName}", invocation.Method.Name);
if(e is AutoCacheExceptionWrapper exceptionWrapper)
{
if (_options.ThrowOnError)
{
throw exceptionWrapper.OriginalException;
}
_logger.LogWarning(
"Cache operation failed, falling back to method execution for {MethodName}",
invocation.Method.Name
);
}
if (!proceeded && invocation.ReturnValue == null)
{
await invocation.ProceedAsync(); // 👈 Fallback to actual method execution
}
}
}
private async Task<(object?, bool)> GetOrAddCacheAsync<TResult>(
IAbpMethodInvocation invocation,
CacheAttribute attribute)
{
var proceeded = false;
var result = await _autoCacheManager.GetOrAddAsync(
invocation.TargetObject,
Factory,
invocation.Arguments,
() => new DistributedCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = GetExpiration(
attribute.AbsoluteExpirationRelativeToNow,
_options.DefaultAbsoluteExpirationRelativeToNow),
SlidingExpiration = GetExpiration(
attribute.SlidingExpiration,
_options.DefaultSlidingExpiration)
},
attribute.InvalidateOnEntities,
attribute.Scope,
attribute.ConsiderUow,
attribute.AdditionalCacheKey,
invocation.Method.Name);
return (result, proceeded);
async Task<TResult> Factory()
{
await invocation.ProceedAsync(); // 👈 Execute actual method on cache miss
proceeded = true;
return (TResult)invocation.ReturnValue;
}
}
private static TimeSpan? GetExpiration(long milliseconds, long defaultValue)
{
return milliseconds switch
{
0 => defaultValue > 0 ? TimeSpan.FromMilliseconds(defaultValue) : null,
< 0 => null,
_ => TimeSpan.FromMilliseconds(milliseconds)
};
}
}
```
The interceptor intelligently determines whether to serve cached data or execute the actual method.
### Step - 5: Implement the Cache Manager
The `AutoCacheManager` handles the actual cache operations. Create a simplified version:
```csharp
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Logging;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Users;
namespace AutoCache;
public class AutoCacheManager : IScopedDependency
{
private readonly IAutoCacheKeyManager _autoCacheKeyManager;
private readonly ICurrentUser _currentUser;
private readonly ILogger<AutoCacheManager> _logger;
private readonly IAutoCacheMetrics _metrics;
private readonly AutoCacheOptions _options;
public AutoCacheManager(
IAutoCacheKeyManager autoCacheKeyManager,
ICurrentUser currentUser,
ILogger<AutoCacheManager> logger,
IAutoCacheMetrics metrics,
IOptions<AutoCacheOptions> options)
{
_autoCacheKeyManager = autoCacheKeyManager;
_currentUser = currentUser;
_logger = logger;
_metrics = metrics;
_options = options.Value;
}
public async Task<TResult> GetOrAddAsync<TResult>(
object? caller,
Func<Task<TResult>> func,
object?[]? parameters = null,
Func<DistributedCacheEntryOptions>? optionsFactory = null,
Type[]? invalidateOnEntities = null,
AutoCacheScope scope = AutoCacheScope.Global,
bool considerUow = false,
string? additionalCacheKey = null,
[CallerMemberName] string methodName = "")
{
if (!_options.Enabled)
{
return await func(); // 👈 Caching disabled, execute directly
}
var callerType = caller != null ? ProxyHelper.GetUnProxiedType(caller) : GetType();
parameters ??= [];
// Generate unique cache key based on method, parameters, and scope
var cacheKey = GenerateCacheKey<TResult>(
callerType.Name,
additionalCacheKey,
methodName,
parameters,
scope);
var (cachedResult, exception, wasHit) = await GetOrAddCacheAsync(
cacheKey,
func,
optionsFactory,
considerUow
);
// Record metrics
if (wasHit)
{
_metrics.RecordHit(cacheKey);
}
else
{
_metrics.RecordMiss(cacheKey);
}
if (exception != null)
{
_metrics.RecordError(cacheKey, exception);
if (_options.ThrowOnError)
{
throw exception;
}
}
return cachedResult;
}
private string GenerateCacheKey<TResult>(
string callerTypeName,
string? additionalCacheKey,
string methodName,
object?[] parameters,
AutoCacheScope scope)
{
var keyBuilder = new StringBuilder();
keyBuilder.Append($"{callerTypeName}:{methodName}");
// Add parameters to key
foreach (var param in parameters)
{
keyBuilder.Append($":{param}");
}
// Add scope-specific segments
if (scope.HasFlag(AutoCacheScope.CurrentUser) && _currentUser.Id.HasValue)
{
keyBuilder.Append($":user:{_currentUser.Id}"); // 👈 User-specific cache key
}
if (scope.HasFlag(AutoCacheScope.AuthenticatedUser))
{
keyBuilder.Append($":auth:{_currentUser.IsAuthenticated}");
}
if (!string.IsNullOrEmpty(additionalCacheKey))
{
keyBuilder.Append($":{additionalCacheKey}");
}
return keyBuilder.ToString();
}
// Additional methods for cache retrieval and storage...
}
```
The manager generates unique cache keys based on method signatures, parameters, and scope settings.
### Step - 6: Implement Cache Invalidation
When entities change, related caches must be cleared. Create `AutoCacheInvalidationHandler.cs`:
```csharp
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Events;
using Volo.Abp.EventBus;
using Volo.Abp.Uow;
namespace AutoCache;
public class AutoCacheInvalidationHandler<TEntity> :
ILocalEventHandler<EntityChangedEventData<TEntity>>
where TEntity : class, IEntity
{
private readonly IAutoCacheKeyManager _autoCacheKeyManager;
private readonly ILogger<AutoCacheInvalidationHandler<TEntity>> _logger;
private readonly IUnitOfWorkManager _unitOfWorkManager;
public AutoCacheInvalidationHandler(
IAutoCacheKeyManager autoCacheKeyManager,
ILogger<AutoCacheInvalidationHandler<TEntity>> logger,
IUnitOfWorkManager unitOfWorkManager)
{
_autoCacheKeyManager = autoCacheKeyManager;
_logger = logger;
_unitOfWorkManager = unitOfWorkManager;
}
public async Task HandleEventAsync(EntityChangedEventData<TEntity> eventData)
{
try
{
var entityType = typeof(TEntity);
var context = new RemoveCacheKeyContext
{
Keys = eventData.Entity.GetKeys()!
};
// Clear cache after unit of work completes
if(_unitOfWorkManager.Current != null)
{
_unitOfWorkManager.Current.OnCompleted(async () =>
{
await _autoCacheKeyManager.RemoveCacheAndCacheKeys(entityType, context); // 👈 Invalidate cache
});
}
else
{
await _autoCacheKeyManager.RemoveCacheAndCacheKeys(entityType, context);
}
}
catch (Exception e)
{
_logger.LogError(
e,
"Error occurred while clearing cache for entity type {EntityType}",
typeof(TEntity).FullName
);
}
}
}
```
![Cache Invalidation Flow](./images/cache-invalidation-flow.svg)
This handler listens to entity change events and automatically clears related caches. The invalidation happens after the unit of work completes to ensure data consistency.
### Step - 7: Configure AutoCache in Your Application
Add the `AutoCacheModule` to your application module dependencies:
```csharp
[DependsOn(
typeof(AutoCacheModule), // 👈 Add AutoCache module
typeof(AbpCachingStackExchangeRedisModule),
// ... other modules
)]
public class YourApplicationModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AutoCacheOptions>(options =>
{
options.Enabled = true; // 👈 Enable caching
options.DefaultAbsoluteExpirationRelativeToNow = 3600000; // 1 hour
options.DefaultSlidingExpiration = 600000; // 10 minutes
options.ThrowOnError = false; // Fallback to method execution on cache errors
});
// Configure Redis (if using distributed cache)
Configure<AbpDistributedCacheOptions>(options =>
{
options.KeyPrefix = "YourApp:";
});
}
}
```
### Step - 8: Use Automatic Caching in Application Services
Now comes the easy part - using automatic caching! Simply add the `[Cache]` attribute to your methods:
```csharp
using AutoCache;
[Authorize(AutoCacheDemoPermissions.Books.Default)]
public class BookAppService : ApplicationService, IBookAppService
{
private readonly IRepository<Book, Guid> _repository;
private readonly AutoCacheManager _autoCacheManager;
public BookAppService(IRepository<Book, Guid> repository, AutoCacheManager autoCacheManager)
{
_repository = repository;
_autoCacheManager = autoCacheManager;
}
// Cache this method, invalidate when Book entity changes
[Cache(typeof(Book), Scope = AutoCacheScope.Global)]
public virtual async Task<BookDto> GetAsync(Guid id)
{
// You can also use AutoCacheManager directly for nested caching
var book = await _autoCacheManager.GetOrAddAsync(
this,
async () => await _repository.GetAsync(id),
[id], // 👈 Method parameters
invalidateOnEntities: [typeof(Book)],
scope: AutoCacheScope.Entity);
return ObjectMapper.Map<Book, BookDto>(book!);
}
// Cache book list, invalidate when any Book changes
[Cache(typeof(Book))]
public virtual async Task<PagedResultDto<BookDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{
var queryable = await _repository.GetQueryableAsync();
var query = queryable
.OrderBy(input.Sorting.IsNullOrWhiteSpace() ? "Name" : input.Sorting)
.Skip(input.SkipCount)
.Take(input.MaxResultCount);
var books = await AsyncExecuter.ToListAsync(query);
var totalCount = await AsyncExecuter.CountAsync(queryable);
return new PagedResultDto<BookDto>(
totalCount,
ObjectMapper.Map<List<Book>, List<BookDto>>(books)
);
}
// No caching on write operations
[Authorize(AutoCacheDemoPermissions.Books.Create)]
public async Task<BookDto> CreateAsync(CreateUpdateBookDto input)
{
var book = ObjectMapper.Map<CreateUpdateBookDto, Book>(input);
await _repository.InsertAsync(book); // 👈 This will trigger cache invalidation
return ObjectMapper.Map<Book, BookDto>(book);
}
}
```
**What Happens Here:**
1. When `GetAsync` is called, the interceptor checks the cache
2. On cache miss, the actual method executes and the result is cached
3. When `CreateAsync` inserts a `Book`, the invalidation handler clears all caches related to `Book`
4. Next call to `GetAsync` will fetch fresh data
## Advanced Features
### User-Specific Caching
For user-specific data, use `AutoCacheScope.CurrentUser`:
```csharp
[Cache(typeof(Order), Scope = AutoCacheScope.CurrentUser)]
public virtual async Task<List<OrderDto>> GetMyOrdersAsync()
{
var orders = await _orderRepository.GetListAsync(x => x.UserId == CurrentUser.Id);
return ObjectMapper.Map<List<Order>, List<OrderDto>>(orders);
}
```
Each user gets their own cache entry, automatically invalidated when their orders change.
### Custom Cache Keys
For fine-grained control, add custom cache key segments:
```csharp
[Cache(
typeof(Product),
Scope = AutoCacheScope.Global,
AdditionalCacheKey = "featured"
)]
public virtual async Task<List<ProductDto>> GetFeaturedProductsAsync()
{
// Only featured products are cached separately
return await GetProductsByCategoryAsync("Featured");
}
```
### Performance Metrics
Monitor cache performance using `IAutoCacheMetrics`:
```csharp
public class CacheMonitoringService : ITransientDependency
{
private readonly IAutoCacheMetrics _metrics;
public CacheMonitoringService(IAutoCacheMetrics metrics)
{
_metrics = metrics;
}
public AutoCacheStatistics GetStatistics()
{
return _metrics.GetStatistics(); // 👈 Get hit rate, miss count, error count
}
}
```
## Testing the Application
### 1. Run the Application
```bash
abp new BookStore -u mvc -d ef
cd BookStore
dotnet run --project src/BookStore.Web
```
### 2. Test Cache Behavior
Create a simple test to verify caching:
```csharp
[Fact]
public async Task Should_Cache_Book_Results()
{
// First call - cache miss
var book1 = await _bookAppService.GetAsync(testBookId);
// Second call - cache hit (should be faster)
var book2 = await _bookAppService.GetAsync(testBookId);
book1.Name.ShouldBe(book2.Name);
}
[Fact]
public async Task Should_Invalidate_Cache_On_Update()
{
// Cache the book
var book1 = await _bookAppService.GetAsync(testBookId);
// Update the book
await _bookAppService.UpdateAsync(testBookId, new CreateUpdateBookDto
{
Name = "Updated Name"
});
// Fetch again - should get updated data (cache was invalidated)
var book2 = await _bookAppService.GetAsync(testBookId);
book2.Name.ShouldBe("Updated Name");
}
```
### 3. Monitor Cache Performance
Check your application logs for cache metrics:
```
[INF] Cache Hit: BookAppService:GetAsync:book-id-123 (Response Time: 5ms)
[INF] Cache Miss: BookAppService:GetListAsync (Response Time: 156ms)
[INF] Cache Invalidation: Book entity changed, cleared 3 cache entries
```
## Key Takeaways
**Automatic caching reduces boilerplate code** - Just add `[Cache]` attribute to methods instead of manual cache management
**Smart invalidation keeps data fresh** - Entity changes automatically clear related caches without manual intervention
**Multiple scoping options** - Support for global, user-specific, authenticated, and entity-level caching strategies
**Built-in fallback handling** - Gracefully falls back to method execution if caching fails
**Performance monitoring** - Track cache hits, misses, and errors for optimization
## Conclusion
Automatic method-level caching dramatically simplifies performance optimization in ABP Framework applications. By using attributes and interceptors, you can add sophisticated caching behavior without cluttering your business logic with cache management code.
The system we've built provides intelligent cache invalidation, multiple scoping strategies, and built-in monitoring - all while maintaining clean, readable code. Whether you're building a small application or an enterprise system, this approach scales elegantly and integrates seamlessly with ABP's architecture.
Ready to implement this in your project? The complete working implementation is available in the [AbpAutoCacheDemo repository](https://github.com/salihozkara/AbpAutoCacheDemo). You can clone the repository, explore the code, and even extract the `src/AutoCache` folder to use it as a standalone library in your own ABP applications. The [main implementation commit](https://github.com/salihozkara/AbpAutoCacheDemo/commit/946df1fc07de6eddd26eb14013a09968cd59329b) shows all the components working together, including interceptor registration, cache key management, and automatic invalidation handlers.r you're building a small application or an enterprise system, this approach scales elegantly and integrates seamlessly with ABP's architecture.
Ready to implement this in your project? Check out the complete working example in the repository linked below, and start improving your application's performance today!
### See Also
- [ABP Caching Documentation](https://abp.io/docs/latest/framework/fundamentals/caching)
- [Interceptors in ABP](https://abp.io/docs/latest/framework/infrastructure/interceptors)
- [Event Bus Documentation](https://abp.io/docs/latest/framework/infrastructure/event-bus)
- [Sample Project on GitHub](https://github.com/salihozkara/AbpAutoCacheDemo)
---
## References
- [ABP Framework Documentation](https://docs.abp.io)
- [Redis Distributed Caching](https://redis.io/docs/)
- [Aspect-Oriented Programming Patterns](https://en.wikipedia.org/wiki/Aspect-oriented_programming)

1
docs/en/Community-Articles/2025-12-06-Implement-Automatic-Method-Level-Caching-in-ABP-Framework/summary.md

@ -0,0 +1 @@
Learn how to implement automatic method-level caching in ABP Framework using attributes and interceptors. This comprehensive guide covers building a reusable cache infrastructure with attribute-based caching, intelligent cache invalidation when entities change, support for multiple cache scopes (Global, CurrentUser, AuthenticatedUser, and Entity), seamless integration with ABP's dynamic proxy system and event bus, and built-in performance metrics for monitoring cache effectiveness in production applications.

BIN
docs/en/images/elsa-studio-wasm.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

97
docs/en/modules/ai-management/index.md

@ -10,8 +10,7 @@
> You must have an ABP Team or a higher license to use this module.
> **⚠️ Important Notice**
> The **AI Management Module** is currently in **preview** and not yet production-ready. The documentation and implementation are subject to change.
> We recommend using this module for **evaluation and experimentation** only, not in production environments for now.
> The **AI Management Module** is currently in **preview**. The documentation and implementation are subject to change.
This module implements AI (Artificial Intelligence) management capabilities on top of the [Artificial Intelligence Workspaces](../../framework/infrastructure/artificial-intelligence/index.md) feature of the ABP Framework and allows to manage workspaces dynamically from the application including UI components and API endpoints.
@ -137,7 +136,7 @@ PreConfigure<AbpAIWorkspaceOptions>(options =>
#### Dynamic Workspaces
* **Created through the UI** or programmatically via `IWorkspaceRepository`
* **Created through the UI** or programmatically via `ApplicationWorkspaceManager` and `IWorkspaceRepository`
* **Fully manageable** - can be created, updated, activated/deactivated, and deleted
* **Stored in database** with all configuration
* **Ideal for** user-customizable AI features
@ -145,15 +144,30 @@ PreConfigure<AbpAIWorkspaceOptions>(options =>
Example (data seeding):
```csharp
var workspace = new Workspace(
name: "CustomerSupportWorkspace",
provider: "OpenAI",
modelName: "gpt-4",
apiKey: "your-api-key"
);
workspace.ApplicationName = ApplicationInfoAccessor.ApplicationName;
workspace.SystemPrompt = "You are a helpful customer support assistant.";
await _workspaceRepository.InsertAsync(workspace);
public class WorkspaceDataSeederContributor : IDataSeedContributor, ITransientDependency
{
private readonly IWorkspaceRepository _workspaceRepository;
private readonly ApplicationWorkspaceManager _applicationWorkspaceManager;
public WorkspaceDataSeederContributor(
IWorkspaceRepository workspaceRepository,
ApplicationWorkspaceManager applicationWorkspaceManager)
{
_workspaceRepository = workspaceRepository;
_applicationWorkspaceManager = applicationWorkspaceManager;
}
public async Task SeedAsync(DataSeedContext context)
{
var workspace = await _applicationWorkspaceManager.CreateAsync(
name: "CustomerSupportWorkspace",
provider: "OpenAI",
modelName: "gpt-4");
workspace.ApiKey = "your-api-key";
workspace.SystemPrompt = "You are a helpful customer support assistant.";
await _workspaceRepository.InsertAsync(workspace);
}
```
### Workspace Naming Rules
@ -179,12 +193,13 @@ The AI Management module defines the following permissions:
In addition to module-level permissions, you can restrict access to individual workspaces by setting the `RequiredPermissionName` property:
```csharp
var workspace = new Workspace(
var workspace = await _applicationWorkspaceManager.CreateAsync(
name: "PremiumWorkspace",
provider: "OpenAI",
modelName: "gpt-4",
requiredPermissionName: "MyApp.PremiumFeatures"
modelName: "gpt-4"
);
// Set a specific permission for the workspace
workspace.RequiredPermissionName = MyAppPermissions.AccessPremiumWorkspaces;
```
When a workspace has a required permission:
@ -437,6 +452,37 @@ Your application acts as a proxy, forwarding these requests to the AI Management
| **3. Client Remote** | No | Remote Service | Remote Service | No | Microservices consuming AI centrally |
| **4. Client Proxy** | No | Remote Service | Remote Service | Yes | API Gateway pattern, proxy services |
## Using Dynamic Workspace Configurations for custom requirements
The AI Management module allows you to access only configuration of a workspace without resolving pre-constructed chat client. This is useful when you want to use a workspace for your own purposes and you don't need to use the chat client.
The `IWorkspaceConfigurationStore` service is used to access the configuration of a workspace. It has multiple implementaations according to the usage scenario.
```csharp
public class MyService
{
private readonly IWorkspaceConfigurationStore _workspaceConfigurationStore;
public MyService(IWorkspaceConfigurationStore workspaceConfigurationStore)
{
_workspaceConfigurationStore = workspaceConfigurationStore;
}
public async Task DoSomethingAsync()
{
// Get the configuration of the workspace that can be managed dynamically.
var configuration = await _workspaceConfigurationStore.GetAsync("MyWorkspace");
// Do something with the configuration
var kernel = Kernel.CreateBuilder()
.AddAzureOpenAIChatClient(
config.ModelName!,
new Uri(config.ApiBaseUrl),
config.ApiKey
)
.Build();
}
}
```
## Implementing Custom AI Provider Factories
While the AI Management module provides built-in support for OpenAI through the `Volo.AIManagement.OpenAI` package, you can easily add support for other AI providers by implementing a custom `IChatClientFactory`.
@ -565,14 +611,14 @@ After implementing and registering your factory:
2. **Through Code** (data seeding):
```csharp
await _workspaceRepository.InsertAsync(new Workspace(
GuidGenerator.Create(),
"MyOllamaWorkspace",
provider: "Ollama",
modelName: "mistral",
apiBaseUrl: "http://localhost:11434",
description: "Local Ollama workspace"
));
var workspace = await _applicationWorkspaceManager.CreateAsync(
name: "MyOllamaWorkspace",
provider: "Ollama",
modelName: "mistral"
);
workspace.ApiBaseUrl = "http://localhost:11434";
workspace.Description = "Local Ollama workspace";
await _workspaceRepository.InsertAsync(workspace);
```
> **Tip**: The provider name you use in `AddFactory<TFactory>("ProviderName")` must match the provider name stored in the workspace configuration in the database.
@ -596,7 +642,7 @@ The following custom repositories are defined:
#### Domain Services
- `ApplicationWorkspaceManager`: Manages workspace operations and validations.
- `WorkspaceConfigurationStore`: Retrieves workspace configuration with caching.
- `WorkspaceConfigurationStore`: Retrieves workspace configuration with caching. Implements `IWorkspaceConfigurationStore` interface.
- `ChatClientResolver`: Resolves the appropriate `IChatClient` implementation for a workspace.
#### Integration Services
@ -625,6 +671,9 @@ Workspace configurations are cached for performance. The cache key format:
WorkspaceConfiguration:{ApplicationName}:{WorkspaceName}
```
### HttpApi Client Layer
- `IntegrationWorkspaceConfigurationStore`: Integration service for remote workspace configuration retrieval. Implements `IWorkspaceConfigurationStore` interface.
The cache is automatically invalidated when workspaces are created, updated, or deleted.
## See Also

85
docs/en/modules/elsa-pro.md

@ -1,10 +1,17 @@
```json
//[doc-seo]
{
"Description": "Integrate Elsa Workflows into your ABP applications with this Pro module. Learn installation and setup for seamless workflow management."
}
```
# Elsa Module (Pro)
> You must have an ABP Team or a higher license to use this module.
This module integrates [Elsa Workflows](https://docs.elsaworkflows.io/) into ABP Framework applications and is designed to make it easy for developers to use Elsa's capabilities within their ABP-based projects. For creating, managing, and customizing workflows themselves, please refer to [the official Elsa documentation](https://docs.elsaworkflows.io/).
## How to install
## How to Install
The Elsa module is not installed in [the startup templates](../solution-templates/layered-web-application) by default and must be installed manually. There are two ways of installing a module into your application and each one of these approaches is explained in the next sections.
@ -37,6 +44,23 @@ After adding the package references, open the module class of the project (e.g.:
> If you are using Blazor Web App, you need to add the `Volo.Elsa.Admin.Blazor.WebAssembly` package to the **{ProjectName}.Blazor.Client.csproj** project and add the `Volo.Elsa.Admin.Blazor.Server` package to the **{ProjectName}.Blazor.csproj** project.
### `AbpElsaAspNetCoreModule` and `AbpElsaIdentityModule`
These two modules generally will be added to your authentication project. Please add `Volo.Elsa.Abp.AspNetCore` and `Volo.Elsa.Abp.Identity` packages to your project and add the `AbpElsaAspNetCoreModule` and `AbpElsaIdentityModule` to the `DependsOn` attribute of your module class based on your project structure:
```xml
<PackageReference Include="Volo.Abp.Elsa.AspNetCore" Version="x.x.x" />
<PackageReference Include="Volo.Abp.Elsa.Identity" Version="x.x.x" />
```
```csharp
[DependsOn(
//...
typeof(AbpElsaAspNetCoreModule),
typeof(AbpElsaIdentityModule)
)]
```
## The Elsa Module
The Elsa Workflows has its own database provider, and also has a Tenant/Role/User system. They are under active development, so the ABP Elsa module is not yet fully integrated. Below is the current status of each module in the ABP's Elsa Module:
@ -56,6 +80,49 @@ The rest of the projects/modules are basically empty and will be implemented in
- `AbpElsaBlazorWebAssemblyModule(Volo.Elsa.Abp.Blazor.WebAssembly)`
- `AbpElsaWebModule(Volo.Elsa.Abp.Web)`
## Configure the Elsa Server
You need to configure Elsa in your ABP application to use its features. You can do that in the `ConfigureServices` method of your `YourElsaAppModule` class as shown below:
> For more information about configuring Elsa, please refer to [the official Elsa documentation](https://docs.elsaworkflows.io/).
```cs
private void ConfigureElsa(ServiceConfigurationContext context, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("Default")!;
context.Services
.AddElsa(elsa => elsa
.UseAbpIdentity(identity => // Use UseAbpIdentity instead of UseIdentity to integrate with ABP Identity module
{
identity.TokenOptions = options => options.SigningKey = "large-signing-key-for-signing-JWT-tokens";
})
.UseWorkflowManagement(management => management.UseEntityFrameworkCore(ef => ef.UseSqlServer(connectionString)))
.UseWorkflowRuntime(runtime => runtime.UseEntityFrameworkCore(ef => ef.UseSqlServer(connectionString)))
.UseScheduling()
.UseJavaScript()
.UseLiquid()
.UseCSharp()
.UseHttp(http => http.ConfigureHttpOptions = options => configuration.GetSection("Http").Bind(options))
.UseWorkflowsApi()
.AddActivitiesFrom<YourElsaAppModule>()
.AddWorkflowsFrom<YourElsaAppModule>()
);
}
```
## Elsa Database Migration
Elsa module uses its own database context and migration system, ABP Elsa module doesn't contain any `aggregate root/entity` at the moment. So, **you don't need to create any initial migration for Elsa module**. You just need to configure the Elsa Services as follows:
```cs
.UseWorkflowManagement(management => management.UseEntityFrameworkCore(ef => ef.UseSqlServer(connectionString)))
.UseWorkflowRuntime(runtime => runtime.UseEntityFrameworkCore(ef => ef.UseSqlServer(connectionString)))
```
When you run your application, Elsa will create its own database tables if they do not exist.
> See [how to configure Elsa Workflows to use different database providers for persistence, including SQL Server, PostgreSQL, and MongoDB](https://docs.elsaworkflows.io/getting-started/database-configuration) for more information.
### Elsa Module Permissions
The Elsa Workflow API endpoints check permissions. Also, it has a `*` wildcard permission to allow all permissions.
@ -72,14 +139,24 @@ You can also grant parts of the permissions to a role or user. It will add the `
### Elsa Studio
Elsa Studio is an **independent** web application that allows you to design, manage, and execute workflows. It is built using **Blazor Server/WebAssembly**.
[Elsa Studio](https://docs.elsaworkflows.io/application-types/elsa-studio) is a **standalone** web application that allows you to design, manage, and execute workflows. It is built using **Blazor Server/WebAssembly**.
`ElsaDemoApp.Studio.WASM` is a sample Blazor WebAssembly project that demonstrates how to use Elsa Studio with ELSA Server with ABP Framework.
> Elsa Studio has its own layout and theme, and you can't integrate it into an ABP Blazor project for now.
![Elsa Studio](../images/elsa-studio-wasm.png)
Please check the [Elsa Workflows - Sample Workflow Demo](../samples/elsa-workflows-demo.md) document to download its source code for review.
#### Elsa Studio Authentication
Elsa Studio requires authentication and there are two ways to authenticate Elsa Studio:
* Password Flow Authentication
* Code Flow Authentication
#### Elsa Studio - Password Flow Authentication
##### Elsa Studio - Password Flow Authentication
The `AbpElsaIdentityModule(Volo.Elsa.Abp.Identity)` module is used to integrate with [ABP Identity module](./identity-pro.md) to check Elsa Studio *username* and *password* against ABP Identity.
@ -109,7 +186,7 @@ Once, you logged in to the application, you can start defining workflows, manage
![elsa-main](../images/elsa-main-page.png)
#### Elsa Studio - Code Flow Authentication
##### Elsa Studio - Code Flow Authentication
ABP applications use [OpenIddict](./openiddict-pro.md) for authentication. So, you can use the [Authorization Code Flow](https://oauth.net/2/grant-types/authorization-code/) to authenticate Elsa Studio.

3
docs/en/modules/identity-pro.md

@ -434,9 +434,10 @@ This module doesn't define any additional distributed event. See the [standard d
## See Also
* [Import External Users](./identity/import-external-users.md)
* [LDAP Login](./identity/idap.md)
* [LDAP Login](./identity/ldap.md)
* [OAuth Login](./identity/oauth-login.md)
* [Periodic Password Change (Password Aging)](./identity/periodic-password-change.md)
* [Two Factor Authentication](./identity/two-factor-authentication.md)
* [Session Management](./identity/session-management.md)
* [Password History](./identity/password-history.md)

0
docs/en/modules/identity/idap.md → docs/en/modules/identity/ldap.md

26
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/TelemetryService.cs

@ -67,7 +67,7 @@ public class TelemetryService : ITelemetryService, IScopedDependency
private Task AddActivityAsync(ActivityContext context)
{
_ = Task.Run(async () =>
var telemetryTask = Task.Run(async () =>
{
using var scope = _serviceScopeFactory.CreateScope();
@ -81,6 +81,30 @@ public class TelemetryService : ITelemetryService, IScopedDependency
telemetryActivitySender);
});
AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{
try
{
telemetryTask.Wait(TimeSpan.FromSeconds(10));
}
catch
{
// ignored
}
};
Console.CancelKeyPress += (_, _) =>
{
try
{
telemetryTask.Wait(TimeSpan.FromSeconds(10));
}
catch
{
// ignored
}
};
return Task.CompletedTask;
}

2
framework/src/Volo.Abp.EntityFrameworkCore.Oracle/Volo.Abp.EntityFrameworkCore.Oracle.csproj

@ -22,8 +22,6 @@
<ItemGroup>
<PackageReference Include="Oracle.EntityFrameworkCore" />
<PackageReference Include="Microsoft.EntityFrameworkCore" VersionOverride="10.0.0-rc.2.25502.107" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" VersionOverride="10.0.0-rc.2.25502.107" />
</ItemGroup>
</Project>

6
framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/AbpSqliteOptions.cs

@ -0,0 +1,6 @@
namespace Volo.Abp.EntityFrameworkCore;
public class AbpSqliteOptions
{
public int? BusyTimeout { get; set; }
}

39
framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Interceptors/SqliteBusyTimeoutSaveChangesInterceptor.cs

@ -0,0 +1,39 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Volo.Abp.EntityFrameworkCore.Interceptors;
/// <summary>
/// https://github.com/dotnet/efcore/issues/29514
/// </summary>
public class SqliteBusyTimeoutSaveChangesInterceptor : SaveChangesInterceptor
{
private readonly string _pragmaCommand;
public SqliteBusyTimeoutSaveChangesInterceptor(int timeoutMilliseconds)
{
_pragmaCommand = $"PRAGMA busy_timeout={timeoutMilliseconds};";
}
public override InterceptionResult<int> SavingChanges(DbContextEventData eventData, InterceptionResult<int> result)
{
if (eventData.Context != null)
{
eventData.Context.Database.ExecuteSqlRaw(_pragmaCommand);
}
return result;
}
public override async ValueTask<InterceptionResult<int>> SavingChangesAsync(DbContextEventData eventData, InterceptionResult<int> result, CancellationToken cancellationToken = default)
{
if (eventData.Context != null)
{
await eventData.Context.Database.ExecuteSqlRawAsync(_pragmaCommand, cancellationToken: cancellationToken);
}
return await base.SavingChangesAsync(eventData, result, cancellationToken);
}
}

22
framework/src/Volo.Abp.EntityFrameworkCore.Sqlite/Volo/Abp/EntityFrameworkCore/Sqlite/AbpEntityFrameworkCoreSqliteModule.cs

@ -1,4 +1,6 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore.GlobalFilters;
using Volo.Abp.EntityFrameworkCore.Interceptors;
using Volo.Abp.Modularity;
namespace Volo.Abp.EntityFrameworkCore.Sqlite;
@ -8,11 +10,31 @@ namespace Volo.Abp.EntityFrameworkCore.Sqlite;
)]
public class AbpEntityFrameworkCoreSqliteModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(options =>
{
options.BusyTimeout = 5000;
});
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
Configure<AbpEfCoreGlobalFilterOptions>(options =>
{
options.UseDbFunction = true;
});
var sqliteOptions = context.Services.ExecutePreConfiguredActions<AbpSqliteOptions>();
if (sqliteOptions.BusyTimeout.HasValue)
{
Configure<AbpDbContextOptions>(options =>
{
options.ConfigureDefaultOnConfiguring((dbContext, dbContextOptionsBuilder) =>
{
dbContextOptionsBuilder.AddInterceptors(new SqliteBusyTimeoutSaveChangesInterceptor(sqliteOptions.BusyTimeout.Value));
}, overrideExisting: false);
});
}
}
}

51
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContextOptions.cs

@ -26,11 +26,11 @@ public class AbpDbContextOptions
internal Dictionary<Type, List<object>> ConventionActions { get; }
internal Action<DbContext, ModelBuilder>? DefaultOnModelCreatingAction { get; set; }
internal Action<DbContext, DbContextOptionsBuilder>? DefaultOnConfiguringAction { get; set; }
internal Dictionary<Type, List<object>> OnModelCreatingActions { get; }
internal Action<DbContext, DbContextOptionsBuilder>? DefaultOnConfiguringAction { get; set; }
internal Dictionary<Type, List<object>> OnConfiguringActions { get; }
public AbpDbContextOptions()
@ -58,11 +58,18 @@ public class AbpDbContextOptions
DefaultConfigureAction = action;
}
public void ConfigureDefaultConvention([NotNull] Action<DbContext, ModelConfigurationBuilder> action)
public void ConfigureDefaultConvention([NotNull] Action<DbContext, ModelConfigurationBuilder> action, bool overrideExisting = false)
{
Check.NotNull(action, nameof(action));
DefaultConventionAction = action;
if (overrideExisting)
{
DefaultConventionAction = action;
}
else
{
DefaultConventionAction += action;
}
}
public void ConfigureConventions<TDbContext>([NotNull] Action<TDbContext, ModelConfigurationBuilder> action)
@ -83,18 +90,18 @@ public class AbpDbContextOptions
actions.Add(action);
}
public void ConfigureDefaultOnModelCreating([NotNull] Action<DbContext, ModelBuilder> action)
{
Check.NotNull(action, nameof(action));
DefaultOnModelCreatingAction = action;
}
public void ConfigureDefaultOnConfiguring([NotNull] Action<DbContext, DbContextOptionsBuilder> action)
public void ConfigureDefaultOnModelCreating([NotNull] Action<DbContext, ModelBuilder> action, bool overrideExisting = false)
{
Check.NotNull(action, nameof(action));
DefaultOnConfiguringAction = action;
if (overrideExisting)
{
DefaultOnModelCreatingAction = action;
}
else
{
DefaultOnModelCreatingAction += action;
}
}
public void ConfigureOnModelCreating<TDbContext>([NotNull] Action<TDbContext, ModelBuilder> action)
@ -114,7 +121,21 @@ public class AbpDbContextOptions
actions.Add(action);
}
public void ConfigureDefaultOnConfiguring([NotNull] Action<DbContext, DbContextOptionsBuilder> action, bool overrideExisting = false)
{
Check.NotNull(action, nameof(action));
if (overrideExisting)
{
DefaultOnConfiguringAction = action;
}
else
{
DefaultOnConfiguringAction += action;
}
}
public void ConfigureOnConfiguring<TDbContext>([NotNull] Action<TDbContext, DbContextOptionsBuilder> action)
where TDbContext : AbpDbContext<TDbContext>
{

30
framework/src/Volo.Abp.EventBus.Kafka/Volo/Abp/EventBus/Kafka/KafkaDistributedEventBus.cs

@ -168,7 +168,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
GetOrCreateHandlerFactories(eventType).Locking(factories => factories.Clear());
}
protected async override Task PublishToEventBusAsync(Type eventType, object eventData)
protected override async Task PublishToEventBusAsync(Type eventType, object eventData)
{
var headers = new Headers
{
@ -193,7 +193,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
unitOfWork.AddOrReplaceDistributedEvent(eventRecord);
}
public async override Task PublishFromOutboxAsync(
public override async Task PublishFromOutboxAsync(
OutgoingEventInfo outgoingEvent,
OutboxConfig outboxConfig)
{
@ -206,13 +206,18 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
headers.Add(EventBusConsts.CorrelationIdHeaderName, System.Text.Encoding.UTF8.GetBytes(outgoingEvent.GetCorrelationId()!));
}
await PublishAsync(
var result = await PublishAsync(
AbpKafkaEventBusOptions.TopicName,
outgoingEvent.EventName,
outgoingEvent.EventData,
headers
);
if (result.Status != PersistenceStatus.Persisted)
{
throw new AbpException($"Failed to publish event '{outgoingEvent.EventName}' to topic '{AbpKafkaEventBusOptions.TopicName}'. Status: {result.Status}");
}
using (CorrelationIdProvider.Change(outgoingEvent.GetCorrelationId()))
{
await TriggerDistributedEventSentAsync(new DistributedEventSent()
@ -224,7 +229,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
}
}
public async override Task PublishManyFromOutboxAsync(IEnumerable<OutgoingEventInfo> outgoingEvents, OutboxConfig outboxConfig)
public override async Task PublishManyFromOutboxAsync(IEnumerable<OutgoingEventInfo> outgoingEvents, OutboxConfig outboxConfig)
{
var producer = ProducerPool.Get(AbpKafkaEventBusOptions.ConnectionName);
var outgoingEventArray = outgoingEvents.ToArray();
@ -242,7 +247,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
headers.Add(EventBusConsts.CorrelationIdHeaderName, System.Text.Encoding.UTF8.GetBytes(outgoingEvent.GetCorrelationId()!));
}
producer.Produce(
var result = await producer.ProduceAsync(
AbpKafkaEventBusOptions.TopicName,
new Message<string, byte[]>
{
@ -251,6 +256,11 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
Headers = headers
});
if (result.Status != PersistenceStatus.Persisted)
{
throw new AbpException($"Failed to publish event '{outgoingEvent.EventName}' to topic '{AbpKafkaEventBusOptions.TopicName}'. Status: {result.Status}");
}
using (CorrelationIdProvider.Change(outgoingEvent.GetCorrelationId()))
{
await TriggerDistributedEventSentAsync(new DistributedEventSent()
@ -263,7 +273,7 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
}
}
public async override Task ProcessFromInboxAsync(
public override async Task ProcessFromInboxAsync(
IncomingEventInfo incomingEvent,
InboxConfig inboxConfig)
{
@ -290,12 +300,16 @@ public class KafkaDistributedEventBus : DistributedEventBusBase, ISingletonDepen
return Serializer.Serialize(eventData);
}
private Task PublishAsync(string topicName, Type eventType, object eventData, Headers headers)
private async Task PublishAsync(string topicName, Type eventType, object eventData, Headers headers)
{
var eventName = EventNameAttribute.GetNameOrDefault(eventType);
var body = Serializer.Serialize(eventData);
return PublishAsync(topicName, eventName, body, headers);
var result = await PublishAsync(topicName, eventName, body, headers);
if (result.Status != PersistenceStatus.Persisted)
{
throw new AbpException($"Failed to publish event '{eventName}' to topic '{topicName}'. Status: {result.Status}");
}
}
private Task<DeliveryResult<string, byte[]>> PublishAsync(

18
framework/src/Volo.Abp.Kafka/Volo/Abp/Kafka/ProducerPool.cs

@ -17,7 +17,7 @@ public class ProducerPool : IProducerPool, ISingletonDependency
protected ConcurrentDictionary<string, Lazy<IProducer<string, byte[]>>> Producers { get; }
protected TimeSpan TotalDisposeWaitDuration { get; set; } = TimeSpan.FromSeconds(10);
protected TimeSpan DefaultTransactionsWaitDuration { get; set; } = TimeSpan.FromSeconds(30);
public ILogger<ProducerPool> Logger { get; set; }
@ -41,8 +41,10 @@ public class ProducerPool : IProducerPool, ISingletonDependency
{
var producerConfig = new ProducerConfig(Options.Connections.GetOrDefault(connection).ToDictionary(k => k.Key, v => v.Value));
Options.ConfigureProducer?.Invoke(producerConfig);
producerConfig.Acks ??= Acks.All;
producerConfig.EnableIdempotence ??= true;
return new ProducerBuilder<string, byte[]>(producerConfig).Build();
})).Value;
}
@ -70,7 +72,7 @@ public class ProducerPool : IProducerPool, ISingletonDependency
foreach (var producer in Producers.Values)
{
var poolItemDisposeStopwatch = Stopwatch.StartNew();
try
{
producer.Value.Dispose();
@ -78,19 +80,19 @@ public class ProducerPool : IProducerPool, ISingletonDependency
catch
{
}
poolItemDisposeStopwatch.Stop();
remainingWaitDuration = remainingWaitDuration > poolItemDisposeStopwatch.Elapsed
? remainingWaitDuration.Subtract(poolItemDisposeStopwatch.Elapsed)
: TimeSpan.Zero;
}
poolDisposeStopwatch.Stop();
Logger.LogInformation(
$"Disposed Kafka Producer Pool ({Producers.Count} producers in {poolDisposeStopwatch.Elapsed.TotalMilliseconds:0.00} ms).");
if (poolDisposeStopwatch.Elapsed.TotalSeconds > 5.0)
{
Logger.LogWarning(

30
framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/TenantResolver.cs

@ -1,6 +1,8 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
@ -8,25 +10,31 @@ namespace Volo.Abp.MultiTenancy;
public class TenantResolver : ITenantResolver, ITransientDependency
{
private readonly IServiceProvider _serviceProvider;
private readonly AbpTenantResolveOptions _options;
public ILogger<TenantResolver> Logger { get; set; }
protected IServiceProvider ServiceProvider { get; }
protected AbpTenantResolveOptions Options { get; }
public TenantResolver(IOptions<AbpTenantResolveOptions> options, IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
_options = options.Value;
Logger = NullLogger<TenantResolver>.Instance;
ServiceProvider = serviceProvider;
Options = options.Value;
}
public virtual async Task<TenantResolveResult> ResolveTenantIdOrNameAsync()
{
var result = new TenantResolveResult();
using (var serviceScope = _serviceProvider.CreateScope())
Logger.LogDebug("Starting resolving tenant...");
using (var serviceScope = ServiceProvider.CreateScope())
{
var context = new TenantResolveContext(serviceScope.ServiceProvider);
foreach (var tenantResolver in _options.TenantResolvers)
foreach (var tenantResolver in Options.TenantResolvers)
{
Logger.LogDebug("Trying to resolve tenant through '{TenantResolverName}'...", tenantResolver.Name);
await tenantResolver.ResolveAsync(context);
result.AppliedResolvers.Add(tenantResolver.Name);
@ -34,15 +42,21 @@ public class TenantResolver : ITenantResolver, ITransientDependency
if (context.HasResolvedTenantOrHost())
{
result.TenantIdOrName = context.TenantIdOrName;
Logger.LogDebug("Tenant resolved by '{TenantResolverName}' as '{TenantIdOrName}'.", tenantResolver.Name, result.TenantIdOrName ?? "Host");
break;
}
}
}
if (result.TenantIdOrName.IsNullOrEmpty() && !string.IsNullOrWhiteSpace(_options.FallbackTenant))
if (result.TenantIdOrName.IsNullOrEmpty() && !string.IsNullOrWhiteSpace(Options.FallbackTenant))
{
result.TenantIdOrName = _options.FallbackTenant;
result.TenantIdOrName = Options.FallbackTenant;
result.AppliedResolvers.Add(TenantResolverNames.FallbackTenant);
Logger.LogDebug("No tenant resolved. Using fallback tenant as '{FallbackTenant}'.", result.TenantIdOrName);
}
else if (result.TenantIdOrName.IsNullOrEmpty())
{
Logger.LogDebug("No tenant resolved.");
}
return result;

1
framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs

@ -30,6 +30,7 @@ public class AbpEntityFrameworkCoreTestModule : AbpModule
public override void PreConfigureServices(ServiceConfigurationContext context)
{
TestEntityExtensionConfigurator.Configure();
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)

9
latest-versions.json

@ -1,4 +1,13 @@
[
{
"version": "9.3.7",
"releaseDate": "",
"type": "stable",
"message": "",
"leptonx": {
"version": "4.3.7"
}
},
{
"version": "10.0.1",
"releaseDate": "",

5
modules/audit-logging/test/Volo.Abp.AuditLogging.EntityFrameworkCore.Tests/Volo/Abp/AuditLogging/EntityFrameworkCore/AbpAuditLoggingEntityFrameworkCoreTestModule.cs

@ -16,6 +16,11 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore;
)]
public class AbpAuditLoggingEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/background-jobs/test/Volo.Abp.BackgroundJobs.EntityFrameworkCore.Tests/Volo/Abp/BackgroundJobs/EntityFrameworkCore/AbpBackgroundJobsEntityFrameworkCoreTestModule.cs

@ -16,6 +16,11 @@ namespace Volo.Abp.BackgroundJobs.EntityFrameworkCore;
)]
public class AbpBackgroundJobsEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/blob-storing-database/test/Volo.Abp.BlobStoring.Database.EntityFrameworkCore.Tests/EntityFrameworkCore/BlobStoringDatabaseEntityFrameworkCoreTestModule.cs

@ -15,6 +15,11 @@ namespace Volo.Abp.BlobStoring.Database.EntityFrameworkCore;
)]
public class BlobStoringDatabaseEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/blogging/test/Volo.Blogging.EntityFrameworkCore.Tests/Volo/Blogging/EntityFrameworkCore/BloggingEntityFrameworkCoreTestModule.cs

@ -18,6 +18,11 @@ namespace Volo.Blogging.EntityFrameworkCore
{
private SqliteConnection _sqliteConnection;
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
_sqliteConnection = CreateDatabaseAndGetConnection();

1
modules/cms-kit/test/Volo.CmsKit.EntityFrameworkCore.Tests/EntityFrameworkCore/CmsKitEntityFrameworkCoreTestModule.cs

@ -20,6 +20,7 @@ public class CmsKitEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
context.Services.AddDataMigrationEnvironment();
}

5
modules/docs/test/Volo.Docs.EntityFrameworkCore.Tests/Volo/Docs/EntityFrameworkCore/DocsEntityFrameworkCoreTestModule.cs

@ -15,6 +15,11 @@ namespace Volo.Docs.EntityFrameworkCore
)]
public class DocsEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/feature-management/test/Volo.Abp.FeatureManagement.EntityFrameworkCore.Tests/Volo/Abp/FeatureManagement/EntityFrameworkCore/AbpFeatureManagementEntityFrameworkCoreTestModule.cs

@ -19,6 +19,11 @@ namespace Volo.Abp.FeatureManagement.EntityFrameworkCore;
)]
public class AbpFeatureManagementEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/identity/test/Volo.Abp.Identity.EntityFrameworkCore.Tests/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreTestModule.cs

@ -18,6 +18,11 @@ namespace Volo.Abp.Identity.EntityFrameworkCore;
)]
public class AbpIdentityEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/openiddict/test/Volo.Abp.OpenIddict.EntityFrameworkCore.Tests/Volo/Abp/OpenIddict/EntityFrameworkCore/OpenIddictEntityFrameworkCoreTestModule.cs

@ -20,6 +20,11 @@ namespace Volo.Abp.OpenIddict.EntityFrameworkCore;
)]
public class OpenIddictEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

2
modules/permission-management/test/Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests/Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests.csproj

@ -15,10 +15,10 @@
<ProjectReference Include="..\..\src\Volo.Abp.PermissionManagement.EntityFrameworkCore\Volo.Abp.PermissionManagement.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Volo.Abp.PermissionManagement.Domain.Tests\Volo.Abp.PermissionManagement.Domain.Tests.csproj" />
<ProjectReference Include="..\Volo.Abp.PermissionManagement.TestBase\Volo.Abp.PermissionManagement.TestBase.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EntityFrameworkCore.Sqlite\Volo.Abp.EntityFrameworkCore.Sqlite.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

40
modules/permission-management/test/Volo.Abp.PermissionManagement.EntityFrameworkCore.Tests/Volo/Abp/PermissionManagement/EntityFrameworkCore/AbpPermissionManagementEntityFrameworkCoreTestModule.cs

@ -1,36 +1,62 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.Sqlite;
using Volo.Abp.Modularity;
using Volo.Abp.Threading;
using Volo.Abp.Uow;
using Microsoft.Data.Sqlite;
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore;
[DependsOn(
typeof(AbpPermissionManagementEntityFrameworkCoreModule),
typeof(AbpPermissionManagementTestBaseModule))]
typeof(AbpPermissionManagementTestBaseModule),
typeof(AbpEntityFrameworkCoreSqliteModule)
)]
public class AbpPermissionManagementEntityFrameworkCoreTestModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddEntityFrameworkInMemoryDatabase();
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
var databaseName = Guid.NewGuid().ToString();
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();
Configure<AbpDbContextOptions>(options =>
{
options.Configure(abpDbContextConfigurationContext =>
{
abpDbContextConfigurationContext.DbContextOptions.UseInMemoryDatabase(databaseName);
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection);
});
});
Configure<AbpUnitOfWorkDefaultOptions>(options =>
{
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
});
context.Services.AddAlwaysDisableUnitOfWorkTransaction();
}
private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:");
connection.Open();
new PermissionManagementDbContext(
new DbContextOptionsBuilder<PermissionManagementDbContext>().UseSqlite(connection).Options
).GetService<IRelationalDatabaseCreator>().CreateTables();
return connection;
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var task = context.ServiceProvider.GetRequiredService<AbpPermissionManagementDomainModule>().GetInitializeDynamicPermissionsTask();

1
modules/setting-management/src/Volo.Abp.SettingManagement.Installer/AngularInstallationInfo.json

@ -2,6 +2,7 @@
"packages":[
{
"name": "@abp/ng.setting-management",
"keepPackageInPackageJson": true,
"appRoutingModuleConfiguration":{
"routes":[
"{ path: 'setting-management', loadChildren: () => import('@abp/ng.setting-management').then(c => c.createRoutes()),}"

5
modules/setting-management/test/Volo.Abp.SettingManagement.EntityFrameworkCore.Tests/Volo/Abp/SettingManagement/EntityFrameworkCore/AbpSettingManagementEntityFrameworkCoreTestModule.cs

@ -17,6 +17,11 @@ namespace Volo.Abp.SettingManagement.EntityFrameworkCore;
)]
public class AbpSettingManagementEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

5
modules/tenant-management/test/Volo.Abp.TenantManagement.EntityFrameworkCore.Tests/Volo/Abp/TenantManagement/EntityFrameworkCore/AbpTenantManagementEntityFrameworkCoreTestModule.cs

@ -17,6 +17,11 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore;
)]
public class AbpTenantManagementEntityFrameworkCoreTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null);
}
public override void ConfigureServices(ServiceConfigurationContext context)
{
var sqliteConnection = CreateDatabaseAndGetConnection();

BIN
source-code/Volo.Abp.BasicTheme.SourceCode/Volo.Abp.BasicTheme.SourceCode.zip

Binary file not shown.

BIN
source-code/Volo.ClientSimulation.SourceCode/Volo.ClientSimulation.SourceCode.zip

Binary file not shown.
Loading…
Cancel
Save