Browse Source

Merge branch 'dev' into net10.0

pull/23609/head
maliming 5 months ago
parent
commit
397c4451f1
  1. 1
      Directory.Packages.props
  2. 3
      abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json
  3. 213
      docs/en/Community-Articles/2025-08-25-App-Services-vs-Domain-Services/POST.md
  4. BIN
      docs/en/Community-Articles/2025-08-25-App-Services-vs-Domain-Services/cover.png
  5. 338
      docs/en/Community-Articles/2025-08-25-AutoMapper-Alternatives/AutoMapper-Alternatives.md
  6. BIN
      docs/en/Community-Articles/2025-08-25-AutoMapper-Alternatives/cover.png
  7. BIN
      docs/en/Community-Articles/2025-08-25-AutoMapper-Alternatives/mapster-mapperly-community-powers.png
  8. 174
      docs/en/Community-Articles/2025-08-27-Building-a-permission-based-authorization-system-for-net-core/POST.md
  9. BIN
      docs/en/Community-Articles/2025-08-27-Building-a-permission-based-authorization-system-for-net-core/cover-image.png
  10. BIN
      docs/en/Community-Articles/2025-08-27-Building-a-permission-based-authorization-system-for-net-core/permission-management-module.png
  11. 169
      docs/en/Community-Articles/2025-08-27-backcompat-rest-apis-ms-dotnet/article.md
  12. BIN
      docs/en/Community-Articles/2025-08-27-backcompat-rest-apis-ms-dotnet/cover.png
  13. 29
      docs/en/Community-Articles/2025-09-02-training-campaign/post.md
  14. BIN
      docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/1.png
  15. BIN
      docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/2.png
  16. 335
      docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/POST.md
  17. BIN
      docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/cover.png
  18. 76
      docs/en/cli/index.md
  19. 4
      docs/en/docs-nav.json
  20. 7
      docs/en/dynamic-proxying-interceptors.md
  21. 13
      docs/en/framework/api-development/standard-apis/configuration.md
  22. 49
      docs/en/framework/architecture/domain-driven-design/application-services.md
  23. 11
      docs/en/framework/infrastructure/entity-cache.md
  24. 213
      docs/en/framework/infrastructure/interceptors.md
  25. 208
      docs/en/framework/ui/angular/form-validation.md
  26. 17
      docs/en/modules/cms-kit/index.md
  27. 5
      docs/en/modules/docs.md
  28. 2
      docs/en/others/why-abp-platform.md
  29. 9
      docs/en/release-info/migration-guides/pro/openiddict-microservice.md
  30. 2
      docs/en/solution-templates/guide.md
  31. 47
      docs/en/tutorials/book-store/part-01.md
  32. 46
      docs/en/tutorials/book-store/part-03.md
  33. 14
      docs/en/tutorials/book-store/part-08.md
  34. 74
      docs/en/tutorials/book-store/part-09.md
  35. 47
      docs/en/tutorials/book-store/part-10.md
  36. 17
      docs/en/tutorials/microservice/part-05.md
  37. 22
      docs/en/tutorials/microservice/part-06.md
  38. 22
      docs/en/tutorials/modular-crm/part-03.md
  39. 20
      docs/en/tutorials/modular-crm/part-05.md
  40. 20
      docs/en/tutorials/modular-crm/part-06.md
  41. 47
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/TelemetryApplicationMetricsEnricher.cs
  42. 20
      framework/src/Volo.Abp.Authorization.Abstractions/Properties/AssemblyInfo.cs
  43. 2
      framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs
  44. 18
      framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionDefinitionContext.cs
  45. 2
      framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionGroupDefinition.cs
  46. 5
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/StaticPermissionDefinitionStore.cs
  47. 45
      framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/TelemetryPermissionInfoEnricher.cs
  48. 1
      framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj
  49. 54
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs
  50. 4
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs
  51. 3
      framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs
  52. 13
      framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs
  53. 50
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityContext.cs
  54. 147
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityEvent.cs
  55. 7
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/IHasParentTelemetryActivityEventEnricher.cs
  56. 8
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/ITelemetryActivityEventBuilder.cs
  57. 11
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/ITelemetryActivityEventEnricher.cs
  58. 17
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/ITelemetryActivityStorage.cs
  59. 49
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryActivityEventBuilder.cs
  60. 70
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryActivityEventEnricher.cs
  61. 104
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryApplicationInfoEnricher.cs
  62. 79
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs
  63. 39
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryModuleInfoEnricher.cs
  64. 27
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetrySessionInfoEnricher.cs
  65. 130
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetrySolutionInfoEnricher.cs
  66. 18
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/FailedActivityInfo.cs
  67. 207
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/TelemetryActivityStorage.cs
  68. 16
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/TelemetryActivityStorageState.cs
  69. 34
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/TelemetryPeriod.cs
  70. 34
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/TelemetryJsonExtensions.cs
  71. 12
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/AbpPlatformUrls.cs
  72. 76
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/ActivityNameConsts.cs
  73. 77
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/ActivityPropertyNames.cs
  74. 260
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/DeviceManager.cs
  75. 9
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/AbpTool.cs
  76. 9
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/OperationSystem.cs
  77. 9
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/SessionType.cs
  78. 11
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/SoftwareType.cs
  79. 6
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/TelemetryConsts.cs
  80. 13
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/TelemetryPaths.cs
  81. 9
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Contracts/ISoftwareDetector.cs
  82. 9
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Contracts/ISoftwareInfoProvider.cs
  83. 11
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Contracts/SoftwareInfo.cs
  84. 78
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Core/SoftwareDetector.cs
  85. 76
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/AbpStudioDetector.cs
  86. 48
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/ChromeDetector.cs
  87. 17
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/DotnetSdkDetector.cs
  88. 45
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/FireFoxDetector.cs
  89. 47
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/MsEdgeDetector.cs
  90. 33
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/NodeJsDetector.cs
  91. 77
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/OperatingSystemDetector.cs
  92. 100
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/RiderDetector.cs
  93. 132
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/VisualStudioCodeDetector.cs
  94. 106
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/VisualStudioDetector.cs
  95. 40
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Providers/SoftwareInfoProvider.cs
  96. 135
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/AbpPackageMetadataReader.cs
  97. 10
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/AbpProjectMetaData.cs
  98. 42
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/Cryptography.cs
  99. 46
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/MutexExecutor.cs
  100. 8
      framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/ITelemetryActivitySender.cs

1
Directory.Packages.props

@ -186,5 +186,6 @@
<PackageVersion Include="coverlet.collector" Version="6.0.4" /> <PackageVersion Include="coverlet.collector" Version="6.0.4" />
<PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2" /> <PackageVersion Include="ConfigureAwait.Fody" Version="3.3.2" />
<PackageVersion Include="Fody" Version="6.9.2" /> <PackageVersion Include="Fody" Version="6.9.2" />
<PackageVersion Include="System.Management" Version="9.0.1"/>
</ItemGroup> </ItemGroup>
</Project> </Project>

3
abp_io/AbpIoLocalization/AbpIoLocalization/Www/Localization/Resources/en.json

@ -1910,6 +1910,7 @@
"DoYouSupportCustomABPArchitectures": "Do you support custom ABP architectures?", "DoYouSupportCustomABPArchitectures": "Do you support custom ABP architectures?",
"SupportCustomABPArchitecturesExplanation": "No. Support is only provided for standard ABP solution structures. On the other hand, you can always get support for your custom needs with a paid consultancy from the ABP Team.", "SupportCustomABPArchitecturesExplanation": "No. Support is only provided for standard ABP solution structures. On the other hand, you can always get support for your custom needs with a paid consultancy from the ABP Team.",
"DoesABPCollectAnyPersonalOrTechnicalData": "Does ABP collect any personal or technical data?", "DoesABPCollectAnyPersonalOrTechnicalData": "Does ABP collect any personal or technical data?",
"ABPCollectAnyDataExplanation": "The software may collect information about you and your use of the software, and send that to Volosoft. Volosoft as the software and service provider may use this information to provide services and improve its products & services. You may opt-out of these scenarios, as described in the <a href=\"{0}\">EULA</a> under PRIVACY AND COLLECTION OF PERSONAL DATA topic ." "ABPCollectAnyDataExplanation": "The software may collect information about you and your use of the software, and send that to Volosoft. Volosoft as the software and service provider may use this information to provide services and improve its products & services. You may opt-out of these scenarios, as described in the <a href=\"{0}\">EULA</a> under PRIVACY AND COLLECTION OF PERSONAL DATA topic .",
"InThisDocument": "In this document"
} }
} }

213
docs/en/Community-Articles/2025-08-25-App-Services-vs-Domain-Services/POST.md

@ -0,0 +1,213 @@
# App Services vs Domain Services: Deep Dive into Two Core Service Types in ABP Framework
In ABP's layered architecture, we frequently encounter two types of services that appear similar but serve distinctly different purposes: Application Services and Domain Services. Understanding the differences between them is crucial for building clear and maintainable enterprise applications.
## Architectural Positioning
In ABP's layered architecture:
- **Application Services** reside in the application layer and are responsible for coordinating use case execution
- **Domain Services** reside in the domain layer and are responsible for implementing core business logic
This layered design follows Domain-Driven Design (DDD) principles, ensuring clear separation of business logic and system maintainability.
## Application Services: Use Case Orchestrators
### Core Responsibilities
Application Services are stateless services primarily used to implement application use cases. They act as a bridge between the presentation layer and domain layer, responsible for:
- **Parameter Validation**: Input validation is automatically handled by ABP using data annotations
- **Authorization**: Checking user permissions and access control using `[Authorize]` attribute or manual authorization checks via `IAuthorizationService`
- **Transaction Management**: Methods automatically run as Unit of Work (transactional by default)
- **Use Case Orchestration**: Organizing and coordinating multiple domain objects to complete specific business use cases
- **Data Transformation**: Handling conversion between DTOs and domain objects using ObjectMapper
### Design Principles
1. **DTO Boundaries**: Application service methods should only accept and return DTOs, never directly expose domain entities
2. **Use Case Oriented**: Each method should correspond to a clear user use case
3. **Thin Layer Design**: Avoid implementing complex business logic in application services
### Typical Execution Flow
A standard application service method typically follows this pattern:
```csharp
[Authorize(BookPermissions.Create)] // Declarative authorization
public virtual async Task<BookDto> CreateBookAsync(CreateBookDto input) // input is automatically validated
{
// Get related data
var author = await _authorRepository.GetAsync(input.AuthorId);
// Call domain service to execute business logic (if needed)
// You can also use the entity constructor directly if no complex business logic is required
var book = await _bookManager.CreateAsync(input.Title, author, input.Price);
// Persist changes
await _bookRepository.InsertAsync(book);
// Return DTO
return ObjectMapper.Map<Book, BookDto>(book);
}
```
### Integration Services: Special kind of Application Service
It's worth mentioning that ABP also provides a special type of application service—Integration Services. They are application services marked with the `[IntegrationService]` attribute, designed for inter-module or inter-microservice communication.
We have a community article dedicated to integration services: [Integration Services Explained — What they are, when to use them, and how they behave](https://abp.io/community/articles/integration-services-explained-what-they-are-when-to-use-lienmsy8)
## Domain Services: Guardians of Business Logic
### Core Responsibilities
Domain Services implement core business logic and are particularly needed when:
- **Core domain logic depends on services**: You need to implement logic that requires repositories or other external services
- **Logic spans multiple aggregates**: The business logic is related to more than one aggregate/entity and doesn't properly fit in any single aggregate
- **Complex business rules**: Complex domain rules that don't naturally belong in a single entity
### Design Principles
1. **Domain Object Interaction**: Method parameters and return values should be domain objects (entities, value objects), never DTOs
2. **Business Logic Focus**: Focus on implementing pure business rules
3. **Stateless Design**: Maintain the stateless nature of services
4. **State-Changing Operations Only**: Domain services should only define methods that mutate data, not query methods
5. **No Authorization Logic**: Domain services should not perform authorization checks or depend on current user context
6. **Specific Method Names**: Use descriptive, business-meaningful method names (e.g., `AssignToAsync`) instead of generic names (e.g., `UpdateAsync`)
### Implementation Example
```csharp
public class IssueManager : DomainService
{
private readonly IRepository<Issue, Guid> _issueRepository;
public virtual async Task AssignToAsync(Issue issue, Guid userId)
{
// Business rule: Check user's unfinished task count
var openIssueCount = await _issueRepository.GetCountAsync(i => i.AssignedUserId == userId && !i.IsClosed);
if (openIssueCount >= 3)
{
throw new BusinessException("IssueTracking:ConcurrentOpenIssueLimit");
}
// Execute assignment logic
issue.AssignedUserId = userId;
issue.AssignedDate = Clock.Now;
}
}
```
## Key Differences Comparison
| Dimension | Application Services | Domain Services |
|-----------|---------------------|-----------------|
| **Layer Position** | Application Layer | Domain Layer |
| **Primary Responsibility** | Use Case Orchestration | Business Logic Implementation |
| **Data Interaction** | DTOs | Domain Objects |
| **Callers** | Presentation Layer/Client Applications | Application Services/Other Domain Services |
| **Authorization** | Responsible for permission checks | No authorization logic |
| **Transaction Management** | Manages transaction boundaries (Unit of Work) | Participates in transactions but doesn't manage |
| **Current User Context** | Can access current user information | Should not depend on current user context |
| **Return Types** | Returns DTOs | Returns domain objects only |
| **Query Operations** | Can perform query operations | Should not define GET/query methods |
| **Naming Convention** | `*AppService` | `*Manager` or `*Service` |
## Collaboration Patterns in Practice
In real-world development, these two types of services typically work together:
```csharp
// Application Service
public class BookAppService : ApplicationService
{
private readonly BookManager _bookManager;
private readonly IRepository<Book> _bookRepository;
[Authorize(BookPermissions.Update)]
public virtual async Task<BookDto> UpdatePriceAsync(Guid id, decimal newPrice)
{
var book = await _bookRepository.GetAsync(id);
await _bookManager.ChangePriceAsync(book, newPrice);
await _bookRepository.UpdateAsync(book);
return ObjectMapper.Map<Book, BookDto>(book);
}
}
// Domain Service
public class BookManager : DomainService
{
public virtual async Task ChangePriceAsync(Book book, decimal newPrice)
{
// Domain service focuses on business rules
if (newPrice <= 0)
{
throw new BusinessException("Book:InvalidPrice");
}
if (book.IsDiscounted && newPrice > book.OriginalPrice)
{
throw new BusinessException("Book:DiscountedPriceCannotExceedOriginal");
}
if (book.Price == newPrice)
{
return;
}
// Additional business logic: Check if price change requires approval
if (await RequiresApprovalAsync(book, newPrice))
{
throw new BusinessException("Book:PriceChangeRequiresApproval");
}
book.ChangePrice(newPrice);
}
private Task<bool> RequiresApprovalAsync(Book book, decimal newPrice)
{
// Example business rule: Large price increases require approval
var increasePercentage = ((newPrice - book.Price) / book.Price) * 100;
return Task.FromResult(increasePercentage > 50); // 50% increase threshold
}
}
```
## Best Practice Recommendations
### Application Services
- Create a corresponding application service for each aggregate root
- Use clear naming conventions (e.g., `IBookAppService`)
- Implement standard CRUD operation methods (`GetAsync`, `CreateAsync`, `UpdateAsync`, `DeleteAsync`)
- Avoid inter-application service calls within the same module/application
- Always return DTOs, never expose domain entities directly
- Use the `[Authorize]` attribute for declarative authorization or manual checks via `IAuthorizationService`
- Methods automatically run as Unit of Work (transactional)
- Input validation is handled automatically by ABP
### Domain Services
- Use the `Manager` suffix for naming (e.g., `BookManager`)
- Only define state-changing methods, avoid query methods (use repositories directly in Application Services for queries)
- Throw `BusinessException` with clear, unique error codes for domain validation failures
- Keep methods pure, avoid involving user context or authorization logic
- Accept and return domain objects only, never DTOs
- Use descriptive, business-meaningful method names (e.g., `AssignToAsync`, `ChangePriceAsync`)
- Do not implement interfaces unless there's a specific need for multiple implementations
## Summary
Application Services and Domain Services each have their distinct roles in the ABP framework: Application Services serve as use case orchestrators, handling authorization, validation, transaction management, and DTO transformations; Domain Services focus purely on business logic implementation without any infrastructure concerns. Integration Services are a special type of Application Service designed for inter-service communication.
Correctly understanding and applying these service patterns is key to building high-quality ABP applications. Through clear separation of responsibilities, we can not only build more maintainable code but also flexibly switch between monolithic and microservice architectures—this is precisely the elegance of ABP framework design.
## References
- [Application Services](https://abp.io/docs/latest/framework/architecture/domain-driven-design/application-services)
- [Integration Services](https://abp.io/docs/latest/framework/api-development/integration-services)
- [Domain Services](https://abp.io/docs/latest/framework/architecture/domain-driven-design/domain-services)

BIN
docs/en/Community-Articles/2025-08-25-App-Services-vs-Domain-Services/cover.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 638 KiB

338
docs/en/Community-Articles/2025-08-25-AutoMapper-Alternatives/AutoMapper-Alternatives.md

@ -0,0 +1,338 @@
# Best Free Alternatives to AutoMapper in .NET — Why We Moved to Mapperly
---
## Introduction
[AutoMapper](https://automapper.io/) has been one of the most popular mapping library for .NET apps. It has been free and [open-source](https://github.com/LuckyPennySoftware/AutoMapper) since 2009. On 16 April 2025, Jimmy Bogard (the owner of the project) decided to make it commercial for his own reasons. You can read [this announcement](https://www.jimmybogard.com/automapper-and-mediatr-licensing-update/) about what happened to AutoMapper.
### Why AutoMapper’s licensing change matters
In ABP Framework we have been also using AutoMapper for object mappings. After its commercial transition, we also needed to replace it. Because ABP Framework is open-source and under [LGPL-3.0 license](https://github.com/abpframework/abp#LGPL-3.0-1-ov-file).
**TL;DR**
> That's why, **we decided to replace AutoMapper with Mapperly**.
In this article, we'll discuss the alternatives of AutoMapper so that you can cut down on costs and maximize performance while retaining control over your codebase. Also I'll explain why we chose Mapperly.
Also AutoMapper uses heavily reflection. And reflection comes with a performance cost if used indiscriminately, and compile-time safety is limited. Let's see how we can overcome these...
## Cost-Free Alternatives to AutoMapper
Check out the comparison table for key features vs. AutoMapper.
| | **AutoMapper (Paid)** | **Mapster (Free)** | **Mapperly (Free)** | **AgileMapper (Free)** | **Manual Mapping** |
| ------------------- | ----------------------------------------------- | ----------------------------------------- | -------------------------------------------- | ------------------------------------------- | ------------------------------------------------ |
| **License & Cost** | Paid/commercial | Free, MIT License | Free, MIT License | Free, Apache 2.0 | Free (no library) |
| **Performance** | Slower due to reflection & conventions | Very fast (runtime & compile-time modes) | Very fast (compile-time code generation) | Good, faster than AutoMapper | Fastest (direct assignment) |
| **Ease of Setup** | Easy, but configuration-heavy | Easy, minimal config | Easy, but different approach from AutoMapper | Simple, flexible configuration | Manual coding required |
| **Features** | Rich features, conventions, nested mappings | Strong typed mappings, projection support | Strong typed, compile-time safe mappings | Dynamic & conditional mapping | Whatever you code |
| **Maintainability** | Hidden mappings can be hard to debug | Explicit & predictable | Very explicit, compiler-verified mappings | Readable, good balance | Very explicit, most maintainable |
| **Best For** | Large teams used to AutoMapper & willing to pay | Teams wanting performance + free tool | Teams prioritizing type-safety & performance | Developers needing flexibility & simplicity | Small/medium projects, performance-critical apps |
There are other libraries such as [**ExpressMapper**](https://github.com/fluentsprings/ExpressMapper) **(308 GitHub stars)**, [**ValueInjecter**](https://github.com/omuleanu/ValueInjecter) **(258 GitHub stars)**, [**AgileMapper**](https://github.com/agileobjects/AgileMapper) **(463 GitHub stars)**. These are not very popular but also free and offer a different balance of simplicity and features.
## Why We Chose Mapperly
We filtered down all the alternatives into 2: **Mapster** and **Mapperly**.
The crucial factor was maintainability! As you see from the screenshots below, Mapster is already stopped development. Mapster’s development appears stalled, and its future maintenance is uncertain. On the other hand, Mapperly regularly gets commits. The community support is valuable.
We looked up different alternatives of AutoMapper also, here's the initial issue of AutoMapper replacement [github.com/abpframework/abp/issues/23243](https://github.com/abpframework/abp/issues/23243).
The ABP team started Mapperly integration with this initial commit [github.com/abpframework/abp/commit/178d3f56d42b4e5acb7e349470f4a644d4c5214e](https://github.com/abpframework/abp/commit/178d3f56d42b4e5acb7e349470f4a644d4c5214e). And this is our Mapperly integration package : [github.com/abpframework/abp/tree/dev/framework/src/Volo.Abp.Mapperly.](https://github.com/abpframework/abp/tree/dev/framework/src/Volo.Abp.Mapperly.)
![Community Powers](mapster-mapperly-community-powers.png)
Here are some considerations for developers who are used to ABP and AutoMapper.
### [Mapster](https://github.com/MapsterMapper/Mapster):
* ✔ It is similar to AutoMapper, configuring mappings through code.
* ✔ Support for dependency injection and complex runtime configuration.
* ❌ It is looking additional Mapster maintainers ([Call for additional Mapster maintainers MapsterMapper/Mapster#752](https://github.com/MapsterMapper/Mapster/discussions/752))
### [Mapperly](https://github.com/riok/Mapperly):
- ✔ It generates mapping code(` source generator`) during the build process.
- ✔ It is actively being developed and maintained.
- ❌ It is a static `map` method, which is not friendly to dependency injection.
- ❌ The configuration method is completely different from AutoMapper, and there is a learning curve.
**Mapperly** → generates mapping code at **compile time** using source generators.
**Mapster** → has two modes:
- By default, it uses **runtime code generation** (via expression trees and compilation).
- But with **Mapster.Tool** (source generator), it can also generate mappings at **compile time**.
This is important because it guarantees the mappings are working well. Also they provide type safety and improved performance. Another advantages of these libraries, they eliminate runtime surprises and offer better IDE support.
---
## When Mapperly Will Come To ABP
Mapperly integration will be delivered with ABP v10. If you have already defined AutoMapper configurations, you can still keep and use them. But the framework will use Mapperly. So there'll be 2 mapping integrations in your app. You can also remove AutoMapper from your final application and use one mapping library: Mapperly. It's up to you! Check [AutoMapper pricing table](https://automapper.io/#pricing).
## Migrating from AutoMapper to Mapperly
In ABP v10, we will be migrating from AutoMapper to Mapperly. The document about the migration is not delivered by the time I wrote this article, but you can reach the document in our dev docs branch
* [github.com/abpframework/abp/blob/dev/docs/en/release-info/migration-guides/AutoMapper-To-Mapperly.md](https://github.com/abpframework/abp/blob/dev/docs/en/release-info/migration-guides/AutoMapper-To-Mapperly.md).
Also for ABP, you can check out how you will define DTO mappings based on Mapperly at this document
* [github.com/abpframework/abp/blob/dev/docs/en/framework/infrastructure/object-to-object-mapping.md](https://github.com/abpframework/abp/blob/dev/docs/en/framework/infrastructure/object-to-object-mapping.md)
## Mapping Code Examples for AutoMapper, Mapster, AgileMapper
### AutoMapper vs Mapster vs Mapperly Performance
Here are concise, drop-in **side-by-side C# snippets** that map the same model with AutoMapper, Mapster, AgileMapper, and manual mapping.
Models used in all examples
We'll use these models to show the mapping examples for AutoMapper, Mapster, AgileMapper.
```csharp
public class Order
{
public int Id { get; set; }
public Customer Customer { get; set; } = default!;
public List<OrderLine> Lines { get; set; } = new();
public DateTime CreatedAt { get; set; }
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; } = "";
public string? Email { get; set; }
}
public class OrderLine
{
public int ProductId { get; set; }
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
}
public class OrderDto
{
public int Id { get; set; }
public string CustomerName { get; set; } = "";
public int ItemCount { get; set; }
public decimal Total { get; set; }
public string CreatedAtIso { get; set; } = "";
}
```
#### AutoMapper Example (Paid)
```csharp
public sealed class OrderProfile : Profile
{
public OrderProfile()
{
CreateMap<Order, OrderDto>()
.ForMember(d => d.CustomerName, m => m.MapFrom(s => s.Customer.Name))
.ForMember(d => d.ItemCount, m => m.MapFrom(s => s.Lines.Sum(l => l.Quantity)))
.ForMember(d => d.Total, m => m.MapFrom(s => s.Lines.Sum(l => l.Quantity * l.UnitPrice)))
.ForMember(d => d.CreatedAtIso,m => m.MapFrom(s => s.CreatedAt.ToString("O")));
}
}
// registration
services.AddAutoMapper(typeof(OrderProfile));
// mapping
var dto = mapper.Map<OrderDto>(order);
// EF Core projection (common pattern)
var list = dbContext.Orders
.ProjectTo<OrderDto>(mapper.ConfigurationProvider)
.ToList();
```
**NuGet Packages:**
- https://www.nuget.org/packages/AutoMapper
- https://www.nuget.org/packages/AutoMapper.Extensions.Microsoft.DependencyInjection
---
#### Mapperly (Free, Apache-2.0)
This is compile-time generated mapping.
```csharp
[Mapper] // generates the implementation at build time
public partial class OrderMapper
{
// Simple property mapping: Customer.Name -> CustomerName
[MapProperty(nameof(Order.Customer) + "." + nameof(Customer.Name), nameof(OrderDto.CustomerName))]
public partial OrderDto ToDto(Order source);
// Update an existing target (like MapToExisting)
[MapProperty(nameof(Order.Customer) + "." + nameof(Customer.Name), nameof(OrderDto.CustomerName))]
public partial void UpdateDto(Order source, OrderDto target);
public OrderDto Map(Order s)
{
var d = ToDto(s);
AfterMap(s, d);
return d;
}
public void Map(Order source, OrderDto d)
{
UpdateDto(source, d);
AfterMap(source, d);
}
private void AfterMap(Order source, OrderDto d)
{
d.ItemCount = source.Lines.Sum(l => l.Quantity);
d.Total = source.Lines.Sum(l => l.Quantity * l.UnitPrice);
d.CreatedAtIso = source.CreatedAt.ToString("O");
}
}
//USAGE
var mapper = new OrderMapper();
var order = new Order
{
Id = 1,
Customer = new Customer { Id = 1, Name = "John Doe", Email = "johndoe@abp.io" },
Lines =
[
new OrderLine {ProductId = 1, Quantity = 2, UnitPrice = 10.0m},
new OrderLine {ProductId = 2, Quantity = 1, UnitPrice = 20.0m}
]
};
// Map to a new object
var dto = mapper.Map(order);
// Map to an existing object
var target = new OrderDto();
mapper.Map(order, target);
```
**NuGet Packages:**
* https://www.nuget.org/packages/Riok.Mapperly/
---
#### Mapster Example (Free, MIT)
```csharp
TypeAdapterConfig<Order, OrderDto>.NewConfig()
.Map(d => d.CustomerName, s => s.Customer.Name)
.Map(d => d.ItemCount, s => s.Lines.Sum(l => l.Quantity))
.Map(d => d.Total, s => s.Lines.Sum(l => l.Quantity * l.UnitPrice))
.Map(d => d.CreatedAtIso, s => s.CreatedAt.ToString("O"));
// one-off
var dto = order.Adapt<OrderDto>();
// DI-friendly registration
services.AddSingleton(TypeAdapterConfig.GlobalSettings);
services.AddScoped<IMapper, ServiceMapper>();
// EF Core projection (strong suit)
var mappedList = dbContext.Orders
.ProjectToType<OrderDto>() // Mapster projection
.ToList();
```
**NuGet Packages:**
- https://www.nuget.org/packages/Mapster
- https://www.nuget.org/packages/Mapster.DependencyInjection
- https://www.nuget.org/packages/Mapster.SourceGenerator (for performance improvement)
---
#### AgileMapper Example (Free, Apache-2.0)
```csharp
var mapper = Mapper.CreateNew(cfg =>
{
cfg.WhenMapping
.From<Order>()
.To<OrderDto>()
.Map(ctx => ctx.Source.Customer.Name).To(dto => dto.CustomerName)
.Map(ctx => ctx.Source.Lines.Sum(l => l.Quantity)).To(dto => dto.ItemCount)
.Map(ctx => ctx.Source.Lines.Sum(l => l.Quantity * l.UnitPrice)).To(dto => dto.Total)
.Map(ctx => ctx.Source.CreatedAt.ToString("O")).To(dto => dto.CreatedAtIso);
});
var mappedDto = mapper.Map(order).ToANew<OrderDto>();
```
**NuGet Packages:**
* https://www.nuget.org/packages/AgileObjects.AgileMapper
---
#### Manual (Pure) Mapping (no library)
Straightforward, fastest, and most explicit. Good for simple applications which doesn't need long term maintenance. Hand-written mapping is faster, safer, and more maintainable. And for tiny mappings, you can still use manual mapping.
* Examples of when manual mapping is better than libraries.
```csharp
public static class OrderMapping
{
public static OrderDto ToDto(this Order s) => new()
{
Id = s.Id,
CustomerName = s.Customer.Name,
ItemCount = s.Lines.Sum(l => l.Quantity),
Total = s.Lines.Sum(l => l.Quantity * l.UnitPrice),
CreatedAtIso = s.CreatedAt.ToString("O")
};
}
// usage
var dto = order.ToDto();
// EF Core projection (best for perf + SQL translation)
var mappedList = dbContext.Orders.Select(s => new OrderDto
{
Id = s.Id,
CustomerName = s.Customer.Name,
ItemCount = s.Lines.Sum(l => l.Quantity),
Total = s.Lines.Sum(l => l.Quantity * l.UnitPrice),
CreatedAtIso = s.CreatedAt.ToString("O")
}).ToList();
```
### Conclusion
If you rely on AutoMapper today, it’s time to evaluate alternatives. For ABP Framework, we chose **Mapperly** due to active development, strong community, and compile-time performance. But your team may prefer **Mapster** for flexibility or even manual mapping for small apps. Your requirements might be different, your project is not a framework so you decide the best one for you.

BIN
docs/en/Community-Articles/2025-08-25-AutoMapper-Alternatives/cover.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 KiB

BIN
docs/en/Community-Articles/2025-08-25-AutoMapper-Alternatives/mapster-mapperly-community-powers.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 163 KiB

174
docs/en/Community-Articles/2025-08-27-Building-a-permission-based-authorization-system-for-net-core/POST.md

@ -0,0 +1,174 @@
# Building a Permission-Based Authorization System for ASP.NET Core
In this article, we'll explore different authorization approaches in ASP.NET Core and examine how ABP's permission-based authorization system works.
First, we'll look at some of the core authorization types that come with ASP.NET Core, such as role-based, claims-based, policy-based, and resource-based authorization. We'll briefly review the pros and cons of each approach.
Then, we'll dive into [ABP's Permission-Based Authorization System](https://abp.io/docs/latest/framework/fundamentals/authorization#permission-system). This is a more advanced approach that gives you fine-grained control over what users can do in your application. We'll also explore ABP's Permission Management Module, which makes managing permissions through the UI easily.
## Understanding ASP.NET Core Authorization Types
Before diving into permission-based authorization, let's examine some of the core authorization types available in ASP.NET Core:
- **[Role-Based Authorization](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-9.0)** checks if the current user belongs to specific roles (like **"Admin"** or **"User"**) and grants access based on these roles. (For example, only users in the **"Manager"** role can access the employee salary management page.)
- **[Claims-Based Authorization](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/claims?view=aspnetcore-9.0)** uses key-value pairs (claims) that describe user attributes, such as age, department, or security clearance. (For example, only users with a **"Department=Finance"** claim can view financial reports.) This provides more granular control but requires careful claim management (such as grouping claims under policies).
- **[Policy-Based Authorization](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-9.0)** combines multiple requirements (roles, claims, custom logic) into reusable policies. It offers flexibility and centralized management, and **this is exactly why ABP's permission system is built on top of it!** (We'll discuss this in more detail later.)
- **[Resource-Based Authorization](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/resourcebased?view=aspnetcore-9.0)** determines access by examining both the user and the specific item they want to access. (For example, a user can edit only their own blog posts, not others' posts.) Unlike policy-based authorization which applies the same rules everywhere, resource-based authorization makes decisions based on the actual data being accessed, requiring more complex implementation.
Here's a quick comparison of these approaches:
| Authorization Type | Pros | Cons |
|-------------------|------|------|
| **Role-Based** | Simple implementation, easy to understand | Becomes inflexible with complex role hierarchies |
| **Claims-Based** | Granular control, flexible user attributes | Complex claim management, potential for claim explosion |
| **Policy-Based** | Centralized logic, combines multiple requirements | Can become complex with numerous policies |
| **Resource-Based** | Fine-grained per-resource control | Implementation complexity, resource-specific code |
## What is Permission-Based Authorization?
Permission-based authorization takes a different approach from other authorization types by defining specific permissions (like **"CreateUser"**, **"DeleteOrder"**, **"ViewReports"**) that represent granular actions within your application. These permissions can be assigned to users directly or through roles, providing both flexibility and clear action-based access control.
ABP Framework's permission system is built on top of this approach and extends ASP.NET Core's policy-based authorization system, working seamlessly with it.
## ABP Framework's Permission System
ABP extends [ASP.NET Core Authorization](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/introduction?view=aspnetcore-9.0) by adding **permissions** as automatic [policies](https://learn.microsoft.com/en-us/aspnet/core/security/authorization/policies?view=aspnetcore-9.0) and allows the authorization system to be used in application services as well.
This system provides a clean abstraction while maintaining full compatibility with ASP.NET Core's authorization infrastructure.
ABP also provides a [Permission Management Module](https://abp.io/docs/latest/modules/permission-management) that offers a complete UI and API for managing permissions. This allows you to easily manage permissions in the UI, assign permissions to roles or users, and much more. (We'll see how to use it in the following sections.)
### Defining Permissions in ABP
In ABP, permissions are defined in classes (typically under the `*.Application.Contracts` project) that inherit from the `PermissionDefinitionProvider` class. Here's how you can define permissions for a book management system:
```csharp
public class BookStorePermissionDefinitionProvider : PermissionDefinitionProvider
{
public override void Define(IPermissionDefinitionContext context)
{
var bookStoreGroup = context.AddGroup("BookStore");
var booksPermission = bookStoreGroup.AddPermission("BookStore.Books", L("Permission:Books"));
booksPermission.AddChild("BookStore.Books.Create", L("Permission:Books.Create"));
booksPermission.AddChild("BookStore.Books.Edit", L("Permission:Books.Edit"));
booksPermission.AddChild("BookStore.Books.Delete", L("Permission:Books.Delete"));
}
private static LocalizableString L(string name)
{
return LocalizableString.Create<BookStoreResource>(name);
}
}
```
ABP automatically discovers this class and registers the permissions/policies in the system. You can then assign these permissions/policies to users/roles. There are two ways to do this:
* Using the [Permission Management Module](https://abp.io/docs/latest/modules/permission-management)
* Using the `IPermissionManager` service (via code)
#### Setting Permissions to Roles and Users via Permission Management Module
When you define a permission, it also becomes usable in the ASP.NET Core authorization system as a **policy name**. If you are using the [Permission Management Module](https://abp.io/docs/latest/modules/permission-management), you can manage the permissions through the UI:
![](permission-management-module.png)
In the permission management UI, you can grant permissions to roles and users through the **Role Management** and **User Management** pages within the "permissions" modals. You can then easily check these permissions in your code. In the screenshot above, you can see the permission modal for the user's page, clearly showing the permissions granted to the user by their role. (**(R)** in the UI indicates that the permission is granted by one of the current user's roles.)
#### Setting Permissions to Roles and Users via Code
You can also set permissions for roles and users programmatically. You just need to inject the `IPermissionManager` service and use its `SetForRoleAsync` and `SetForUserAsync` methods (or similar methods):
```csharp
public class MyService : ITransientDependency
{
private readonly IPermissionManager _permissionManager;
public MyService(IPermissionManager permissionManager)
{
_permissionManager = permissionManager;
}
public async Task GrantPermissionForUserAsync(Guid userId, string permissionName)
{
await _permissionManager.SetForUserAsync(userId, permissionName, true);
}
public async Task ProhibitPermissionForUserAsync(Guid userId, string permissionName)
{
await _permissionManager.SetForUserAsync(userId, permissionName, false);
}
}
```
### Checking Permissions in AppServices and Controllers
ABP provides multiple ways to check permissions. The most common approach is using the `[Authorize]` attribute and passing the permission/policy name.
Here is an example of how to check permissions in an application service:
```csharp
[Authorize("BookStore.Books")]
public class BookAppService : ApplicationService, IBookAppService
{
[Authorize("BookStore.Books.Create")]
public async Task<BookDto> CreateAsync(CreateBookDto input)
{
//logic here
}
}
```
> Notice that you can use the `[Authorize]` attribute at both class and method levels. In the example above, the `CreateAsync` method is marked with the `[Authorize]` attribute, so it will check the user's permission before executing the method. Since the application service class also has a permission requirement, both permissions must be granted to the user to execute the method!
And here is an example of how to check permissions in a controller:
```csharp
[Authorize("BookStore.Books")]
public class CreateBookController : AbpController
{
//omitted for brevity...
}
```
### Programmatic Permission Checking
To conditionally control authorization in your code, you can use the `IAuthorizationService` service:
```csharp
public class BookAppService : ApplicationService, IBookAppService
{
public async Task<BookDto> CreateAsync(CreateBookDto input)
{
// Checks the permission and throws an exception if the user does not have the permission
await AuthorizationService.CheckAsync(BookStorePermissions.Books.Create);
// Your logic here
}
public async Task<bool> CanUserCreateBooksAsync()
{
// Checks if the permission is granted for the current user
return await AuthorizationService.IsGrantedAsync(BookStorePermissions.Books.Create);
}
}
```
You can use the `IAuthorizationService`'s helpful methods for authorization checking, as shown in the example above:
- `IsGrantedAsync` checks if the current user has the given permission.
- `CheckAsync` throws an exception if the current user does not have the given permission.
- `AuthorizeAsync` checks if the current user has the given permission and returns an `AuthorizationResult`, which has a `Succeeded` property that you can use to verify if the user has the permission.
Also notice that we did not inject the `IAuthorizationService` in the constructor, because we are using the `ApplicationService` base class, which already provides property injection for it. This means we can directly use it in our application services, just like other helpful base services (such as `ICurrentUser` and `ICurrentTenant`).
## Conclusion
Permission-based authorization in ABP Framework provides a powerful and flexible approach to securing your applications. By building on ASP.NET Core's policy-based authorization, ABP offers a clean abstraction that simplifies permission management while maintaining the full power of the underlying system.
The ability to check permissions in both application services and controllers makes ABP Framework's authorization system very flexible and powerful, yet easy to use.
Additionally, the Permission Management Module makes it very easy to manage permissions and roles through the UI. You can learn more about how it works in the [documentation](https://abp.io/docs/latest/modules/permission-management).

BIN
docs/en/Community-Articles/2025-08-27-Building-a-permission-based-authorization-system-for-net-core/cover-image.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 KiB

BIN
docs/en/Community-Articles/2025-08-27-Building-a-permission-based-authorization-system-for-net-core/permission-management-module.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

169
docs/en/Community-Articles/2025-08-27-backcompat-rest-apis-ms-dotnet/article.md

@ -0,0 +1,169 @@
# Best Practices for Designing Backward‑Compatible REST APIs in a Microservice Solution for .NET Developers
## Introduction
With microservice architecture, each service develops and ships independently at its own pace, and clients infrequently update in lockstep. **Backward compatibility** means that when you release new versions, current consumers continue to function without changing code. This article provides a practical, 6–7 minute tutorial specific to **.NET developers**.
---
## What Counts as “Breaking”? (and what doesn’t)
A change is **breaking** if a client that previously conformed can **fail at compile time or runtime**, or exhibit **different business‑critical behavior**, **without** changing that client in any way. In other words: if an old client needs to be altered in order to continue functioning as it did, your change is breaking.
### Examples of breaking changes
- **Deleting or renaming an endpoint** or modifying its URL/route.
- **Making an existing field required** (e.g., requiring `address`).
- **Data type or format changes** (e.g., `price: string``price: number`, or date format changes).
- **Altering default behavior or ordering** that clients implicitly depend on (hidden contracts).
- **Changing the error model** or HTTP status codes in a manner that breaks pre-existing error handling.
- **Renaming fields** or **making optional fields required** in requests or responses.
- **Reinterpreting semantics** (e.g., `status="closed"` formerly included archived items, but no longer does).
### Examples of non‑breaking changes
- **Optional fields or query parameters can be added** (clients may disregard them).
- **Adding new enum values** (if the clients default to a safe behavior for unrecognized values).
- **Adding a new endpoint** while leaving the previous one unchanged.
- **Performance enhancements** that leave input/output unchanged.
- **Including metadata** (e.g., pagination links) without changing the current payload shape.
> Golden rule: **Old clients should continue to work exactly as they did before—without any changes.**
---
## Versioning Strategy
Versioning is your master control lever for managing change. Typical methods:
1) **URI Segment** (simplest)
```
GET /api/v1/orders
GET /api/v2/orders
```
Pros: Cache/gateway‑friendly; explicit in docs. Cons: URL noise.
2) **Header‑Based**
```
GET /api/orders
x-api-version: 2.0
```
Pros: Clean URLs; multiple reader support. Cons: Needs proxy/CDN rules.
3) **Media Type**
Accept: application/json;v=2
Pros: Semantically accurate. <br> Cons: More complicated to test and implement. <br> **Recommendation:** For the majority of teams, favor **URI segments**, with an optional **`x-api-version`** header for flexibility.
### Quick Setup in ASP.NET Core (Asp.Versioning)
```csharp
// Program.cs
using Asp.Versioning;
builder.Services.AddControllers();
builder.Services.AddApiVersioning(o =>
{
o.DefaultApiVersion = new ApiVersion(1, 0);
o.AssumeDefaultVersionWhenUnspecified = true;
o.ReportApiVersions = true; // response header: api-supported-versions
o.ApiVersionReader = ApiVersionReader.Combine(
new UrlSegmentApiVersionReader(),
new HeaderApiVersionReader("x-api-version")
);
});
builder.Services.AddVersionedApiExplorer(o =>
{
o.GroupNameFormat = "'v'VVV"; // v1, v2
o.SubstituteApiVersionInUrl = true;
});
```
```csharp
// Controller
using Asp.Versioning;
[ApiController]
[Route("api/v{version:apiVersion}/orders")]
public class OrdersController : ControllerBase
{
[HttpGet]
[ApiVersion("1.0", Deprecated = true)]
public IActionResult GetV1() => Ok(new { message = "v1" });
[HttpGet]
[MapToApiVersion("2.0")]
public IActionResult GetV2() => Ok(new { message = "v2", includes = new []{"items"} });
}
```
---
## Schema Evolution Playbook (JSON & DTO)
Obey the following rules for compatibility‑safe evolution:
- **Add‑only changes**: Favor adding **optional** fields; do not remove/rename fields.
- **Maintain defaults**: When the new field is disregarded, the old functionality must not change.
- **Enum extension**: Clients should handle unknown enum values gracefully (default behavior).
- **Deprecation pipeline**: Mark fields/endpoints as deprecated **at least one version** prior to removal and publicize extensively. - **Stability by contract**: Record any unspoken contracts (ordering, casing, formats) that clients depend on.
### Example: adding a non‑breaking field
```csharp
public record OrderDto(
Guid Id,
decimal Total,
string Currency,
string? SalesChannel // new, optional
);
```
---
## Compatibility‑Safe API Behaviors
- **Error model**: Use a standard structure (e.g., RFC 7807 `ProblemDetails`). Avoid ad‑hoc error shapes on a per-endpoint basis.
- **Versioning/Deprecation communication** through headers:
- `api-supported-versions: 1.0, 2.0`
- `Deprecation: true` (in deprecated endpoints)
- `Sunset: Wed, 01 Oct 2025 00:00:00 GMT` (planned deprecation date)
- **Idempotency**: Use an `Idempotency-Key` header for retry-safe POSTs.
- **Optimistic concurrency**: Utilize `ETag`/`If-Match` to prevent lost updates.
- **Pagination**: Prefer cursor tokens (`nextPageToken`) to protect clients from sorting/index changes.
- **Time**: Employ ISO‑8601 in UTC; record time‑zone semantics and rounding conventions.
---
## Rollout & Deprecation Policy
A good deprecation policy is **announce → coexist → remove**:
1) **Announce**: Release changelog, docs, and comms (mail/Slack) with v2 information and the sunset date.
2) **Coexist**: Operate v1 and v2 side by side. Employ gateway percentage routing for progressive cutover.
3) **Observability**: Monitor errors/latency/usage **by version**. When v1 traffic falls below ~5%, plan for removal. 4) **Remove**: Post sunset date, return **410 (Gone)** with a link to migration documentation.
**Canary & Blue‑Green**: Initialize v2 with a small traffic portion and compare error/latency budgets prior to scaling up.
---
## Contract & Compatibility Testing
- **Consumer‑Driven Contracts**: Write expectations using Pact.NET; verify at provider CI.
- **Golden files / snapshots**: Freeze representative JSON payloads and automatically detect regressions.
- **Version-specific smoke tests**: Maintain separate, minimal test suites for v1 and v2.
- **SemVer discipline**: Minor = backward‑compatible; Major = breaking (avoid when possible).
Minimal example (xUnit + snapshot style):
```csharp
[Fact]
public async Task Orders_v1_contract_should_match_snapshot()
{
var resp = await _client.GetStringAsync("/api/v1/orders");
Approvals.VerifyJson(resp); // snapshot comparison
}
```
---
## Tooling & Docs (for .NET)
- **Asp.Versioning (NuGet)**: API versioning + ApiExplorer integration.
- **Swashbuckle / NSwag**: Generate an OpenAPI definition **for every version** (`/swagger/v1/swagger.json`, `/swagger/v2/swagger.json`). Display both in Swagger UI.
- **Polly**: Client‑side retries/fallbacks to handle transient failures and ensure resilience.
- **Serilog + OpenTelemetry**: Collect metrics/logs/traces by version for observability and SLOs.
Swagger UI configuration by group name:
```csharp
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API v1");
c.SwaggerEndpoint("/swagger/v2/swagger.json", "API v2");
});
```
---
## Conclusion
Backward compatibility is not a version number—it is **disciplined change management**. When you use add‑only schema evolution, a well‑defined versioning strategy, strict contract testing, and rolling rollout, you maintain microservice independence and safeguard consumer experience.

BIN
docs/en/Community-Articles/2025-08-27-backcompat-rest-apis-ms-dotnet/cover.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 755 KiB

29
docs/en/Community-Articles/2025-09-02-training-campaign/post.md

@ -0,0 +1,29 @@
# IMPROVE YOUR ABP SKILLS WITH 33% OFF LIVE TRAININGS!
We have exciting news to share\! As you know, we offer live training packages to help you improve your skills and knowledge of ABP. From September 8th to 19th, we are giving you 33% OFF our live trainings, so you can learn more about the product at a discounted price\!
#### Why Join ABP.IO Training?
ABP training programs are designed to help developers, architects, and teams master the ABP Framework efficiently. Whether you're new to the framework or looking to deepen your knowledge, our courses cover everything you need to build robust and scalable applications with ABP.
#### What You’ll Gain:
✔ Comprehensive live training from ABP Experts
✔ Hands-on learning with real-world applications
✔ Best practices for building modern web applications
✔ Certification to showcase your expertise
#### [Limited-Time 33% Discount – Don’t Miss Out\!](https://abp.io/trainings?utm_source=referral&utm_medium=website&utm_campaign=training_abpblogpost)
For a short period, all training packages are available at a 33% discount. This is a great opportunity to upskill yourself or train your team at a significantly reduced cost.
#### How to Get the Discount?
Simply visit our training page, select your preferred package, add your note if needed and send your training request, that's all\! ABP Training Team will reply to your request via email soon.
#### Take Advantage of This Offer Today
Invest in your skills and advance your career with ABP.IO training. This offer won’t last long, so grab your spot now\!
### 🔗[Sign up for training now and start building with ABP](https://abp.io/trainings?utm_source=referral&utm_medium=website&utm_campaign=training_abpblogpost)\!

BIN
docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

BIN
docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 KiB

335
docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/POST.md

@ -0,0 +1,335 @@
# Keep Track of Your Users in an ASP.NET Core Application
Tracking what users do in your app matters for security, debugging, and business insights. Doing it by hand usually means lots of boilerplate: managing request context, logging operations, tracking entity changes, and more. It adds complexity and makes mistakes more likely.
## Why Applications Need Audit Logs
Audit logs are time-ordered records that show what happened in your app.
A good audit log should capture details for every web request, including:
### 1. Request and Response Details
- Basic info like **URL, HTTP method, browser**, and **HTTP status code**
- Network info like **client IP address** and **user agent**
- **Request parameters** and **response content** when needed
### 2. Operations Performed
- **Controller actions** and **application service method calls** with parameters
- **Execution time** and **duration** for performance tracking
- **Call chains** and **dependencies** where helpful
### 3. Entity Changes
- **Entity changes** that happen during requests
- **Property-level changes**, with old and new values
- **Change types** (create, update, delete) and timestamps
### 4. Exception Information
- **Errors and exceptions** during request execution
- **Exception stack traces** and **error context**
- Clear records of failed operations
### 5. Request Duration
- Key metrics for **measuring performance**
- **Finding bottlenecks** and optimization opportunities
- Useful data for **monitoring system health**
## The Challenge with Doing It by Hand
In ASP.NET Core, developers often use middleware or MVC filters for tracking. Here’s what that looks like and the common problems you’ll hit.
### Using Middleware
Middleware are components in the ASP.NET Core pipeline that run during request processing.
Manual tracking typically requires:
- Writing custom middleware to intercept HTTP requests
- Extracting user info (user ID, username, IP address, and so on)
- Recording request start time and execution duration
- Handling both success and failure cases
- Saving audit data to logs or a database
### Tracking Inside Business Methods
In your business code, you also need to:
- Log the start and end of important operations
- Capture errors and related context
- Link business operations to the request-level audit data
- Make sure you track all critical actions
### Problems with Manual Tracking
Manual tracking has some big downsides:
**Code duplication and maintenance pain**: Each controller ends up repeating similar tracking logic. Changing the rules means touching many places, and it’s easy to miss some.
**Consistency and reliability issues**: Different people implement tracking differently. Exception paths are easy to forget. It’s hard to ensure complete coverage.
**Performance and scalability concerns**: Homegrown tracking can slow the app if not designed well. Tuning and extending it takes effort.
**Entity change tracking is especially hard**. It often requires:
- Recording original values before updates
- Comparing old and new values for each property
- Handling complex types, collections, and navigation properties
- Designing and saving change records
- Capturing data even when exceptions happen
This usually leads to:
- **A lot of code** in every update method
- **Easy-to-miss edge cases** and subtle bugs
- **High maintenance** when entity models change
- **Extra queries and comparisons** that can hurt performance
- **Incomplete coverage** for complex scenarios
## ABP Framework’s Built-in Solution
ABP Framework includes a built-in audit logging system. It solves the problems above and adds useful features on top.
### Simple Setup vs. Manual Tracking
Instead of writing lots of code, you configure it once:
```csharp
// Configure audit log options in the module's ConfigureServices method
Configure<AbpAuditingOptions>(options =>
{
options.IsEnabled = true; // Enable audit log system (default value)
options.IsEnabledForAnonymousUsers = true; // Track anonymous users (default value)
options.IsEnabledForGetRequests = false; // Skip GET requests (default value)
options.AlwaysLogOnException = true; // Always log on errors (default value)
options.HideErrors = true; // Hide audit log errors (default value)
options.EntityHistorySelectors.AddAllEntities(); // Track all entity changes
});
```
```csharp
// Add middleware in the module's OnApplicationInitialization method
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
var app = context.GetApplicationBuilder();
// Add audit log middleware - one line of code solves all problems!
app.UseAuditing();
}
```
By contrast, manual tracking needs middleware, controller logic, exception handling, and often hundreds of lines. With ABP, a couple of lines enable it and it just works.
## What You Get with ABP
Here’s how ABP removes tracking code from your application and still captures what you need.
### 1. Application Services: No Tracking Code
Manual approach: You’d log inside each method and still risk missing cases.
ABP approach: Tracking is automatic—no tracking code in your methods.
```csharp
public class BookAppService : ApplicationService
{
private readonly IRepository<Book, Guid> _bookRepository;
private readonly IRepository<Author, Guid> _authorRepository;
[Authorize(BookPermissions.Create)]
public virtual async Task<BookDto> CreateAsync(CreateBookDto input)
{
// No need to write any tracking code!
// ABP automatically tracks:
// - Method calls and parameters
// - Calling user
// - Execution duration
// - Any exceptions thrown
var author = await _authorRepository.GetAsync(input.AuthorId);
var book = new Book(input.Title, author, input.Price);
await _bookRepository.InsertAsync(book);
return ObjectMapper.Map<Book, BookDto>(book);
}
[Authorize(BookPermissions.Update)]
public virtual async Task<BookDto> UpdateAsync(Guid id, UpdateBookDto input)
{
var book = await _bookRepository.GetAsync(id);
// No need to write any entity change tracking code!
// ABP automatically tracks entity changes:
// - Which properties changed
// - Old and new values
// - When the change happened
book.ChangeTitle(input.Title);
book.ChangePrice(input.Price);
await _bookRepository.UpdateAsync(book);
return ObjectMapper.Map<Book, BookDto>(book);
}
}
```
With manual code, each method might need 20–30 lines for tracking. With ABP, it’s zero—and you still get richer data.
For entity changes, ABP also saves you from writing comparison code. It handles:
- Property change detection
- Recording old and new values
- Complex types and collections
- Navigation property changes
- All with no extra code to maintain
### 2. Entity Change Tracking: One Line to Turn It On
Manual approach: You’d compare properties, serialize complex types, track collection changes, and write to storage.
ABP approach: Mark the entity or select entities globally.
```csharp
// Enable audit log for specific entity - one line of code solves all problems!
[Audited]
public class MyEntity : Entity<Guid>
{
public string Name { get; set; }
public string Description { get; set; }
[DisableAuditing] // Exclude sensitive data - security control
public string InternalNotes { get; set; }
}
```
```csharp
// Or global configuration - batch processing
Configure<AbpAuditingOptions>(options =>
{
// Track all entities - one line of code tracks all entity changes
options.EntityHistorySelectors.AddAllEntities();
// Or use custom selector - precise control
options.EntityHistorySelectors.Add(
new NamedTypeSelector(
"MySelectorName",
type => typeof(IEntity).IsAssignableFrom(type)
)
);
});
```
### 3. Extension Features
Manual approach: Adding custom tracking usually spreads across many places and is hard to test.
ABP approach: Use a contributor for clean, centralized extensions.
```csharp
public class MyAuditLogContributor : AuditLogContributor
{
public override void PreContribute(AuditLogContributionContext context)
{
var currentUser = context.ServiceProvider.GetRequiredService<ICurrentUser>();
// Easily add custom properties - manual implementation needs lots of work
context.AuditInfo.SetProperty(
"MyCustomClaimValue",
currentUser.FindClaimValue("MyCustomClaim")
);
}
public override void PostContribute(AuditLogContributionContext context)
{
// Add custom comments - business logic integration
context.AuditInfo.Comments.Add("Some comment...");
}
}
// Register contributor - one line of code enables extension features
Configure<AbpAuditingOptions>(options =>
{
options.Contributors.Add(new MyAuditLogContributor());
});
```
### 4. Precise Control
Manual approach: You end up with complex conditional logic.
ABP approach: Use attributes for simple, precise control.
```csharp
// Disable audit log for specific controller - precise control
[DisableAuditing]
public class HomeController : AbpController
{
// Health check endpoints won't be audited - avoid meaningless logs
}
// Disable for specific action - method-level control
public class HomeController : AbpController
{
[DisableAuditing]
public async Task<ActionResult> Home()
{
// This action won't be audited - public data access
}
public async Task<ActionResult> OtherActionLogged()
{
// This action will be audited - important business operation
}
}
```
### 5. Visual Management of Audit Logs
ABP also provides a UI to browse and inspect audit logs:
![](1.png)
![](2.png)
## Manual vs. ABP: A Quick Comparison
The benefits of ABP’s audit log system compared to doing it by hand:
| Aspect | Manual Implementation | ABP Audit Logs |
|--------|----------------------|----------------|
| **Setup Complexity** | High — Write middleware, services, repository code | Low — A few lines of config, works out of the box |
| **Code Maintenance** | High — Tracking code spread across the app | Low — Centralized, convention-based |
| **Consistency** | Variable — Depends on discipline | Consistent — Automated and standardized |
| **Performance** | Risky without careful tuning | Built-in optimizations and scope control |
| **Functionality Completeness** | Basic tracking only | Comprehensive by default |
| **Error Handling** | Easy to miss edge cases | Automatic and reliable |
| **Data Integrity** | Manual effort required | Handled by the framework |
| **Extensibility** | Custom work is costly | Rich extension points |
| **Development Efficiency** | Weeks to build | Minutes to enable |
| **Learning Cost** | Understand many details | Convention-based, low effort |
## Why ABP Audit Logs Matter
ABP’s audit logging removes the boilerplate from user tracking in ASP.NET Core apps.
### Core Idea
Manual tracking is error-prone and hard to maintain. ABP gives you a convention-based, automated system that works with minimal setup.
### Key Benefits
ABP runs by convention, so you don’t need repetitive code. You can control behavior at the request, entity, and method levels. It automatically captures request details, operations, entity changes, and exceptions, and you can extend it with contributors when needed.
### Results in Practice
| Metric | Manual Implementation | ABP Implementation | Improvement |
|--------|----------------------|-------------------|-------------|
| Development Time | Weeks | Minutes | **99%+** |
| Lines of Code | Hundreds of lines | 2 lines of config | **99%+** |
| Maintenance Cost | High | Low | **Significant** |
| Functionality Completeness | Basic | Comprehensive | **Significant** |
| Error Rate | Higher risk | Lower risk | **Improved** |
### Recommendation
If you need audit logs, start with ABP’s built-in system. It reduces effort, improves consistency, and stays flexible as your app grows. You can focus on your business logic and let the framework handle the infrastructure.
## References
- [ABP Audit Logging](https://abp.io/docs/latest/framework/infrastructure/audit-logging)
- [ABP Audit Logging UI](https://abp.io/modules/Volo.AuditLogging.Ui)

BIN
docs/en/Community-Articles/2025-09-03-Keep-Track-of-Your-Users-in-an-ASP.NET-Core-Application/cover.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 520 KiB

76
docs/en/cli/index.md

@ -33,44 +33,44 @@ While each command may have a set of options, there are some global options that
Here, is the list of all available commands before explaining their details: Here, is the list of all available commands before explaining their details:
* **`help`**: Shows help on the usage of the ABP CLI. * **[`help`](../cli#help)**: Shows help on the usage of the ABP CLI.
* **`cli`**: Update or remove ABP CLI. * **[`cli`](../cli#cli)**: Update or remove ABP CLI.
* **`new`**: Generates a new solution based on the ABP [startup templates](../solution-templates/index.md). * **[`new`](../cli#new)**: Generates a new solution based on the ABP [startup templates](../solution-templates/index.md).
* **`new-module`**: Generates a new module based on the given template. * **[`new-module`](../cli#new-module)**: Generates a new module based on the given template.
* **`new-package`**: Generates a new package based on the given template. * **[`new-package`](../cli#new-package)**: Generates a new package based on the given template.
* **`update`**: Automatically updates all ABP related NuGet and NPM packages in a solution. * **[`update`](../cli#update)**: Automatically updates all ABP related NuGet and NPM packages in a solution.
* **`clean`**: Deletes all `BIN` and `OBJ` folders in the current folder. * **[`clean`](../cli#clean)**: Deletes all `BIN` and `OBJ` folders in the current folder.
* **`add-package`**: Adds an ABP package to a project. * **[`add-package`](../cli#add-package)**: Adds an ABP package to a project.
* **`add-package-ref`**: Adds package to given project. * **[`add-package-ref`](../cli#add-package-ref)**: Adds package to given project.
* **`install-module`**: Adds a [multi-package application module](../modules/index.md) to a given module. * **[`install-module`](../cli#install-module)**: Adds a [multi-package application module](../modules/index.md) to a given module.
* **`install-local-module`**: Installs a local module to given module. * **[`install-local-module`](../cli#install-local-module)**: Installs a local module to given module.
* **`list-modules`**: Lists names of application modules. * **[`list-modules`](../cli#list-modules)**: Lists names of application modules.
* **`list-templates`**: Lists the names of available templates to create a solution. * **[`list-templates`](../cli#list-templates)**: Lists the names of available templates to create a solution.
* **`get-source`**: Downloads the source code of a module. * **[`get-source`](../cli#get-source)**: Downloads the source code of a module.
* **`add-source-code`**: Downloads the source code and replaces package references with project references. * **[`add-source-code`](../cli#add-source-code)**: Downloads the source code and replaces package references with project references.
* **`init-solution`**: Creates ABP Studio configuration files for a given solution. * **[`init-solution`](../cli#init-solution)**: Creates ABP Studio configuration files for a given solution.
* **`kube-connect`**: Connects to kubernetes environment. (*Available for* ***Business*** *or higher licenses*) * **[`kube-connect`](../cli#kube-connect)**: Connects to kubernetes environment. (*Available for* ***Business*** *or higher licenses*)
* **`kube-intercept`**: Intercepts a service running in Kubernetes environment. (*Available for* ***Business*** *or higher licenses*) * **[`kube-intercept`](../cli#kube-intercept)**: Intercepts a service running in Kubernetes environment. (*Available for* ***Business*** *or higher licenses*)
* **`list-module-sources`**: Lists the remote module sources. * **[`list-module-sources`](../cli#list-module-sources)**: Lists the remote module sources.
* **`add-module-source`**: Adds a remote module source. * **[`add-module-source`](../cli#add-module-source)**: Adds a remote module source.
* **`delete-module-source`**: Deletes a remote module source. * **[`delete-module-source`](../cli#delete-module-source)**: Deletes a remote module source.
* **`generate-proxy`**: Generates client side proxies to use HTTP API endpoints. * **[`generate-proxy`](../cli#generate-proxy)**: Generates client side proxies to use HTTP API endpoints.
* **`remove-proxy`**: Removes previously generated client side proxies. * **[`remove-proxy`](../cli#remove-proxy)**: Removes previously generated client side proxies.
* **`switch-to-preview`**: Switches to the latest preview version of the ABP. * **[`switch-to-preview`](../cli#switch-to-preview)**: Switches to the latest preview version of the ABP.
* **`switch-to-nightly`**: Switches to the latest [nightly builds](../release-info/nightly-builds.md) of the ABP related packages on a solution. * **[`switch-to-nightly`](../cli#switch-to-nightly)**: Switches to the latest [nightly builds](../release-info/nightly-builds.md) of the ABP related packages on a solution.
* **`switch-to-stable`**: Switches to the latest stable versions of the ABP related packages on a solution. * **[`switch-to-stable`](../cli#switch-to-stable)**: Switches to the latest stable versions of the ABP related packages on a solution.
* **`switch-to-local`**: Changes NuGet package references on a solution to local project references. * **[`switch-to-local`](../cli#switch-to-local)**: Changes NuGet package references on a solution to local project references.
* **`upgrade`**: It converts the application to use pro modules. * **[`upgrade`](../cli#upgrade)**: It converts the application to use pro modules.
* **`translate`**: Simplifies to translate localization files when you have multiple JSON [localization](../framework/fundamentals/localization.md) files in a source control repository. * **[`translate`](../cli#translate)**: Simplifies to translate localization files when you have multiple JSON [localization](../framework/fundamentals/localization.md) files in a source control repository.
* **`login`**: Authenticates on your computer with your [abp.io](https://abp.io/) username and password. * **[`login`](../cli#login)**: Authenticates on your computer with your [abp.io](https://abp.io/) username and password.
* **`login-info`**: Shows the current user's login information. * **[`login-info`](../cli#login-info)**: Shows the current user's login information.
* **`logout`**: Logouts from your computer if you've authenticated before. * **[`logout`](../cli#logout)**: Logouts from your computer if you've authenticated before.
* **`bundle`**: Generates script and style references for ABP Blazor and MAUI Blazor project. * **[`bundle`](../cli#bundle)**: Generates script and style references for ABP Blazor and MAUI Blazor project.
* **`install-libs`**: Install NPM Packages for MVC / Razor Pages and Blazor Server UI types. * **[`install-libs`](../cli#install-libs)**: Install NPM Packages for MVC / Razor Pages and Blazor Server UI types.
* **`clear-download-cache`**: Clears the templates download cache. * **[`clear-download-cache`](../cli#clear-download-cache)**: Clears the templates download cache.
* **`check-extensions`**: Checks the latest version of the ABP CLI extensions. * **[`check-extensions`](../cli#check-extensions)**: Checks the latest version of the ABP CLI extensions.
* **`install-old-cli`**: Installs old ABP CLI. * **[`install-old-cli`](../cli#install-old-cli)**: Installs old ABP CLI.
* **`generate-razor-page`**: Generates a page class that you can use it in the ASP NET Core pipeline to return an HTML page. * **[`generate-razor-page`](../cli#generate-razor-page)**: Generates a page class that you can use it in the ASP NET Core pipeline to return an HTML page.
### help ### help

4
docs/en/docs-nav.json

@ -745,6 +745,10 @@
"text": "Image Manipulation", "text": "Image Manipulation",
"path": "framework/infrastructure/image-manipulation.md" "path": "framework/infrastructure/image-manipulation.md"
}, },
{
"text": "Interceptors",
"path": "framework/infrastructure/interceptors.md"
},
{ {
"text": "JSON", "text": "JSON",
"path": "framework/infrastructure/json.md" "path": "framework/infrastructure/json.md"

7
docs/en/dynamic-proxying-interceptors.md

@ -1,7 +0,0 @@
# Dynamic Proxying / Interceptors
This document is planned to be written later.
## See Also
* [Video tutorial](https://abp.io/video-courses/essentials/interception)

13
docs/en/framework/api-development/standard-apis/configuration.md

@ -55,7 +55,16 @@ namespace Acme.BookStore.Web
} }
``` ```
Add your contributor instance to the `AbpApplicationConfigurationOptions`
```csharp
Configure<AbpApplicationConfigurationOptions>(options =>
{
options.Contributors.AddIfNotContains(new MyApplicationConfigurationContributor());
});
```
* `IApplicationConfigurationContributor` defines the `ContributeAsync` method to extend the **application-configuration** endpoint with the specified additional data. * `IApplicationConfigurationContributor` defines the `ContributeAsync` method to extend the **application-configuration** endpoint with the specified additional data.
* You can inject services and perform any logic needed to extend the endpoint as you wish. * You can get services from `context.ServiceProvider` and perform any logic needed to extend the endpoint as you wish.
> Application configuration contributors are automatically discovered by the ABP and executed as a part of the application configuration initialization process. > Application configuration contributors are executed as a part of the application configuration initialization process.

49
docs/en/framework/architecture/domain-driven-design/application-services.md

@ -134,7 +134,7 @@ The `CreateAsync` method above manually creates a `Book` entity from given `Crea
However, in many cases, it's very practical to use **auto object mapping** to set properties of an object from a similar object. ABP provides an [object to object mapping](../../infrastructure/object-to-object-mapping.md) infrastructure to make this even easier. However, in many cases, it's very practical to use **auto object mapping** to set properties of an object from a similar object. ABP provides an [object to object mapping](../../infrastructure/object-to-object-mapping.md) infrastructure to make this even easier.
Object to object mapping provides abstractions and it is implemented by the [AutoMapper](https://automapper.org/) library by default. Object to object mapping provides abstractions and it is implemented by the [Mapperly](https://mapperly.riok.app/) library by default.
Let's create another method to get a book. First, define the method in the `IBookAppService` interface: Let's create another method to get a book. First, define the method in the `IBookAppService` interface:
@ -162,36 +162,32 @@ public class BookDto
} }
```` ````
AutoMapper requires to create a mapping [profile class](https://docs.automapper.org/en/stable/Configuration.html#profile-instances). Example: [Mapperly](https://mapperly.riok.app/) requires to create a mapping class that implements the `MapperBase<Book, BookDto>` class with the `[Mapper]` attribute as follows:
````csharp ```csharp
public class MyProfile : Profile [Mapper]
public partial class BookToBookDtoMapper : MapperBase<Book, BookDto>
{ {
public MyProfile() public override partial BookDto Map(Book source);
{
CreateMap<Book, BookDto>(); public override partial void Map(Book source, BookDto destination);
}
} }
```` ```
You should then register profiles using the `AbpAutoMapperOptions`: Then, if your application uses multiple mapping providers, you should add the following configuration to your module's `ConfigureServices` method to decide which mapping provider to use:
````csharp ````csharp
[DependsOn(typeof(AbpAutoMapperModule))] [DependsOn(typeof(AbpMapperlyModule))]
public class MyModule : AbpModule public class MyModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)
{ {
Configure<AbpAutoMapperOptions>(options => context.Services.AddMapperlyObjectMapper<MyModule>();
{
//Add all mappings defined in the assembly of the MyModule class
options.AddMaps<MyModule>();
});
} }
} }
```` ````
`AddMaps` registers all profile classes defined in the assembly of the given class, typically your module class. It also registers for the [attribute mapping](https://docs.automapper.org/en/stable/Attribute-mapping.html). With this configuration, your module will use [Mapperly](https://mapperly.riok.app/) as the default mapping provider and you don't need to register mapping classes manually.
Then you can implement the `GetAsync` method as shown below: Then you can implement the `GetAsync` method as shown below:
@ -291,16 +287,21 @@ public class CreateUpdateBookDto
} }
```` ````
[Profile](https://docs.automapper.org/en/stable/Configuration.html#profile-instances) class of DTO class. Define the mapping classes for [Mapperly](https://mapperly.riok.app/) as follows:
```csharp ```csharp
public class MyProfile : Profile [Mapper]
public partial class BookToBookDtoMapper : MapperBase<Book, BookDto>
{ {
public MyProfile() public override partial BookDto Map(Book source);
{ public override partial void Map(Book source, BookDto destination);
CreateMap<Book, BookDto>(); }
CreateMap<CreateUpdateBookDto, Book>();
} [Mapper]
public partial class CreateUpdateBookDtoToBookMapper : MapperBase<CreateUpdateBookDto, Book>
{
public override partial Book Map(CreateUpdateBookDto source);
public override partial void Map(CreateUpdateBookDto source, Book destination);
} }
``` ```

11
docs/en/framework/infrastructure/entity-cache.md

@ -88,6 +88,17 @@ public class MyMapperProfile : Profile
} }
``` ```
If you are using [Mapperly](https://mapperly.riok.app/), you can create a new mapping class that implements the `MapperBase<Product, ProductDto>` class with the `[Mapper]` attribute as follows:
```csharp
[Mapper]
public partial class ProductToProductDtoMapper : MapperBase<Product, ProductDto>
{
public override partial ProductDto Map(Product source);
public override partial void Map(Product source, ProductDto destination);
}
```
Now, you can inject the `IEntityCache<ProductDto, Guid>` service wherever you want: Now, you can inject the `IEntityCache<ProductDto, Guid>` service wherever you want:
```csharp ```csharp

213
docs/en/framework/infrastructure/interceptors.md

@ -0,0 +1,213 @@
# Interceptors
ABP provides a powerful interception system that allows you to execute custom logic before and after method calls without modifying the original method code. This is achieved through **dynamic proxying** and is extensively used throughout the ABP framework to implement cross-cutting concerns. ABP's interception is implemented on top of the [Castle DynamicProxy](https://www.castleproject.org/projects/dynamicproxy/) library.
## What is Dynamic Proxying / Interception?
**Interception** is a technique that allows executing additional logic before or after a method call without directly modifying the method's code. This is achieved through **dynamic proxying**, where the runtime generates proxy classes that wrap the original class.
When a method is called on a proxied object:
1. The call is intercepted by the proxy
2. Custom behaviors (like logging, validation, or authorization) can be executed
3. The original method is called
4. Additional logic can be executed after the method completes
This enables **cross-cutting concerns** (logic that applies across many parts of an application) to be handled in a clean, reusable way without code duplication.
## Similarities and Differences with MVC Action/Page Filters
If you are familiar with ASP.NET Core MVC, you've likely used **action filters** or **page filters**. Interceptors are conceptually similar but have some key differences:
### Similarities
* Both allow executing code before and after method execution
* Both are used to implement cross-cutting concerns like validation, logging, caching, or exception handling
* Both support asynchronous operations
### Differences
* **Scope**: Filters are tied to MVC's request pipeline, while interceptors can be applied to **any class or service** in the application
* **Configuration**: Filters are configured via attributes or middleware in MVC, while interceptors in ABP are applied through **dependency injection and dynamic proxies**
* **Target**: Interceptors can target application services, domain services, repositories, and virtually any service resolved from the IoC container—not just web controllers
## How ABP Uses Interceptors
ABP Framework extensively leverages interception to provide built-in features without requiring boilerplate code. Here are some key examples:
### [Unit of Work (UOW)](../architecture/domain-driven-design/unit-of-work.md)
Automatically begins and commits/rolls back a database transaction when entering or exiting an application service method. This ensures data consistency without manual transaction management.
### [Input Validation](../fundamentals/validation.md)
Input DTOs are automatically validated against data annotation attributes and custom validation rules before executing the service logic, providing consistent validation behavior across all services.
### [Authorization](../fundamentals/authorization.md)
Checks user permissions before allowing the execution of application service methods, ensuring security policies are enforced consistently.
### [Feature](./features.md) & [Global Feature](./global-features.md) Checking
Checks if a feature is enabled before executing the service logic, allowing you to conditionally enable or restrict functionality for tenants or the application.
### [Auditing](./audit-logging.md)
Automatically logs who performed an action, when it happened, what parameters were used, and what data was involved, providing comprehensive audit trails.
## Building Your Own Interceptor
You can create custom interceptors in ABP to implement your own cross-cutting concerns.
### Creating an Interceptor
Create a class that inherits from `AbpInterceptor`:
````csharp
using System.Threading.Tasks;
using Volo.Abp.Aspects;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
public class ExecutionTimeLogInterceptor : AbpInterceptor, ITransientDependency
{
private readonly ILogger<ExecutionTimeLogInterceptor> _logger;
public ExecutionTimeLogInterceptor(ILogger<ExecutionTimeLogInterceptor> logger)
{
_logger = logger;
}
public override async Task InterceptAsync(IAbpMethodInvocation invocation)
{
var sw = Stopwatch.StartNew();
_logger.LogInformation($"Executing {invocation.TargetObject.GetType().Name}.{invocation.Method.Name}");
// Proceed to the actual target method
await invocation.ProceedAsync();
sw.Stop();
_logger.LogInformation($"Executed {invocation.TargetObject.GetType().Name}.{invocation.Method.Name} in {sw.ElapsedMilliseconds} ms");
}
}
````
### Register Interceptors
Create a static class that contains the `RegisterIfNeeded` method and register the interceptor in the `PreConfigureServices` method of your module.
The `ShouldIntercept` method is used to determine if the interceptor should be registered for the given type. You can add an `IExecutionTimeLogEnabled` interface and implement it in the classes that you want to intercept.
> `DynamicProxyIgnoreTypes` is static class that contains the types that should be ignored by the interceptor. See [Performance Considerations](#performance-considerations) for more information.
````csharp
// Define an interface to mark the classes that should be intercepted
public interface IExecutionTimeLogEnabled
{
}
````
````csharp
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
// A simple service that added to the DI container and will be intercepted since it implements the `IExecutionTimeLogEnabled` interface
public class SampleExecutionTimeService : IExecutionTimeLogEnabled, ITransientDependency
{
public virtual async Task DoWorkAsync()
{
// Simulate a long-running task to test the interceptor
await Task.Delay(1000);
}
}
````
````csharp
using System;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
public static class ExecutionTimeLogInterceptorRegistrar
{
public static void RegisterIfNeeded(IOnServiceRegistredContext context)
{
if (ShouldIntercept(context.ImplementationType))
{
context.Interceptors.TryAdd<ExecutionTimeLogInterceptor>();
}
}
private static bool ShouldIntercept(Type type)
{
return !DynamicProxyIgnoreTypes.Contains(type) && typeof(IExecutionTimeLogEnabled).IsAssignableFrom(type);
}
}
````
````csharp
public override void PreConfigureServices(ServiceConfigurationContext context)
{
context.Services.OnRegistered(ExecutionTimeLogInterceptorRegistrar.RegisterIfNeeded);
}
````
## Restrictions and Important Notes
### Always use asynchronous methods
For best performance and reliability, implement your service methods as asynchronous to avoid **async over sync**, that can cause unexpected problems, For more information, see [Should I expose synchronous wrappers for asynchronous methods?](https://devblogs.microsoft.com/dotnet/should-i-expose-synchronous-wrappers-for-asynchronous-methods/)
### Virtual Methods Requirement
For **class proxies**, methods need to be marked as `virtual` so that they can be overridden by the proxy. Otherwise, interception will not occur.
````csharp
public class MyService : IExecutionTimeLogEnabled, ITransientDependency
{
// This method CANNOT be intercepted (not virtual)
public void CannotBeIntercepted()
{
}
// This method CAN be intercepted (virtual)
public virtual void CanBeIntercepted()
{
}
}
````
> This restriction does **not** apply to interface-based proxies. If your service implements an interface and is injected via that interface, all methods can be intercepted regardless of the `virtual` keyword.
### Dependency Injection Scope
Interceptors only work when services are resolved from the dependency injection container. Direct instantiation with `new` bypasses interception:
````csharp
// This will NOT be intercepted
var service = new MyService();
service.CannotBeIntercepted();
// This WILL be intercepted (if MyService is registered with DI)
var service = serviceProvider.GetService<MyService>();
service.CanBeIntercepted();
````
### Performance Considerations
Interceptors are generally efficient, but each one adds method-call overhead. Keep the number of interceptors minimal on hot paths.
Castle DynamicProxy can negatively impact performance for certain components, notably ASP.NET Core MVC controllers. See the discussions in [castleproject/Core#486](https://github.com/castleproject/Core/issues/486) and [abpframework/abp#3180](https://github.com/abpframework/abp/issues/3180).
ABP uses interceptors for features like UOW, auditing, and authorization, which rely on dynamic proxy classes. For controllers, prefer implementing cross-cutting concerns with middleware or MVC/Page filters instead of dynamic proxies.
To avoid generating dynamic proxies for specific types, use the static class `DynamicProxyIgnoreTypes` and add the base classes of the types to the list. Subclasses of any listed base class are also ignored. ABP framework already adds some base classes to the list (`ComponentBase, ControllerBase, PageModel, ViewComponent`); you can add more base classes if needed.
> Always use interface-based proxies instead of class-based proxies for better performance.
## See Also
* [Video tutorial: Interceptors in ABP Framework](https://abp.io/video-courses/essentials/interception)
* [Castle DynamicProxy](https://www.castleproject.org/projects/dynamicproxy/)
* [Castle.Core.AsyncInterceptor](https://github.com/JSkimming/Castle.Core.AsyncInterceptor)
* [ASP.NET Core Filters](https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/filters)

208
docs/en/framework/ui/angular/form-validation.md

@ -170,3 +170,211 @@ export const appConfig: ApplicationConfig = {
The error message will be bold and italic now: The error message will be bold and italic now:
<img alt="A required field is cleared and a bold and italic error message appears." src="./images/form-validation---custom-error-template.gif" width="990px" style="max-width:100%"> <img alt="A required field is cleared and a bold and italic error message appears." src="./images/form-validation---custom-error-template.gif" width="990px" style="max-width:100%">
## How to Validate Nested Form Groups
There are multiple ways to validate nested form groups in ABP Angular UI. Below is the first and most common approach, using automatic validation and error messages with nested reactive forms. (A second method will be described in the next section.)
### 1st Way: Automatic Validation and Error Message Using Nested Reactive Forms
ABP Angular UI leverages Angular's reactive forms and the [ngx-validate](https://www.npmjs.com/package/@ngx-validate/core) library to provide a robust, flexible, and user-friendly form validation experience. Whether you build your forms manually or use ABP’s dynamic form generation features, validation and error messages are handled automatically.
#### Key Features
- **Automatic Validation:**
All validation rules defined in your DTOs (such as `[Required]`, `[StringLength]`, `[EmailAddress]`, etc.) are automatically reflected in the Angular form. Error messages are shown under each field without any extra markup.
- **Nested Form Groups and Dynamic Fields:**
For complex data structures, you can group fields or manage dynamic lists using nested `FormGroup` and `FormArray` structures. Validation and error display work seamlessly for both parent and child controls.
- **Dynamic and Extensible Forms:**
With ABP’s extensibility system, you can generate forms dynamically using helpers like `generateFormFromProps` and display them with the `abp-extensible-form` component. This ensures all entity properties (including extension properties) are included in the form and their validation rules are applied.
- **No Extra Boilerplate:**
You do not need to add custom error components or directives for validation. The system works out of the box, including for nested and dynamically generated controls.
#### Real-World Example: Nested Form Groups in the Users Form
Below is a real example from the Users management form in ABP Angular UI, showing how nested form structures and validation are implemented. This example includes both dynamically generated fields (with `abp-extensible-form`) and a dynamic list of roles using `FormArray` and `FormGroup`.
**TypeScript: Building the Form**
```ts
buildForm() {
const data = new FormPropData(this.injector, this.selected);
this.form = generateFormFromProps(data); // Automatically creates form controls from entity and extension properties
this.service.getAssignableRoles().subscribe(({ items }) => {
this.roles = items;
if (this.roles) {
// Dynamic roles list: nested FormArray and FormGroup
this.form.addControl(
'roleNames',
this.fb.array(
this.roles.map(role =>
this.fb.group({
[role.name as string]: [
this.selected?.id
? !!this.selectedUserRoles?.find(userRole => userRole.id === role.id)
: role.isDefault,
],
}),
),
),
);
}
});
}
```
**HTML: Displaying the Form**
```html
<abp-modal [(visible)]="isModalVisible" [busy]="modalBusy">
<ng-template #abpHeader>
<h3>{{ (selected?.id ? 'AbpIdentity::Edit' : 'AbpIdentity::NewUser') | abpLocalization }}</h3>
</ng-template>
<ng-template #abpBody>
@if (form) {
<form [formGroup]="form" (ngSubmit)="save()">
<ul ngbNav #nav="ngbNav" class="nav-tabs">
<li ngbNavItem>
<a ngbNavLink>{{ 'AbpIdentity::UserInformations' | abpLocalization }}</a>
<ng-template ngbNavContent>
<!-- Automatically displays all entity fields and their validation -->
<abp-extensible-form [selectedRecord]="selected"></abp-extensible-form>
</ng-template>
</li>
<li ngbNavItem>
<a ngbNavLink>{{ 'AbpIdentity::Roles' | abpLocalization }}</a>
<ng-template ngbNavContent>
<!-- Dynamic roles list: nested FormArray and FormGroup -->
@for (roleGroup of roleGroups; track $index; let i = $index) {
<div class="form-check mb-2">
<abp-checkbox
[formControl]="roleGroup.controls[roles[i].name]"
[label]="roles[i].name"
></abp-checkbox>
</div>
}
</ng-template>
</li>
</ul>
<div class="mt-2 fade-in-top" [ngbNavOutlet]="nav"></div>
</form>
} @else {
<div class="text-center"><i class="fa fa-pulse fa-spinner" aria-hidden="true"></i></div>
}
</ng-template>
</abp-modal>
```
**Explanation:**
- `abp-extensible-form` automatically generates and displays all entity fields and their validation.
- In the Roles tab, each role is represented by a checkbox, and these checkboxes are managed in a `FormArray`, with each as a `FormGroup`. This is a real-world example of a nested form structure.
- All validation and error messages are shown automatically for both the main form and nested groups.
### 2nd Way: Manual Nested Reactive Forms Without abp-extensible-form
You can also build and validate nested form groups manually, without using `abp-extensible-form` or dynamic helpers. This approach gives you full control over the form structure and is useful for custom or non-entity-based forms.
#### Example: Simple Manual Nested FormGroup
Below is a simple, generic example of a nested reactive form. This form includes a nested `FormGroup` for profile information and demonstrates how to apply validation rules.
**TypeScript: Building the Form**
```ts
import { Component, OnInit, inject } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { NgxValidateCoreModule } from '@ngx-validate/core';
@Component({
selector: 'app-nested-form',
templateUrl: './nested-form.component.html',
standalone: true,
imports: [NgxValidateCoreModule],
})
export class NestedFormComponent implements OnInit {
form: FormGroup;
private fb = inject(FormBuilder);
ngOnInit() {
this.buildForm();
}
buildForm() {
this.form = this.fb.group({
userName: ['', Validators.required],
email: ['', [Validators.required, Validators.email]],
profile: this.fb.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
}),
});
}
submit() {
if (this.form.invalid) {
return;
}
// handle submit
}
}
```
**HTML: Displaying the Form**
```html
<form [formGroup]="form" (ngSubmit)="submit()">
<div class="mb-3">
<label class="form-label">User Name</label>
<input type="text" class="form-control" formControlName="userName" />
</div>
<div class="mb-3">
<label class="form-label">Email</label>
<input type="email" class="form-control" formControlName="email" />
</div>
<div formGroupName="profile" class="card mt-3">
<div class="card-header">
<strong>Profile Details</strong>
</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">First Name</label>
<input type="text" class="form-control" formControlName="firstName" />
</div>
<div class="mb-3">
<label class="form-label">Last Name</label>
<input type="text" class="form-control" formControlName="lastName" />
</div>
</div>
</div>
<hr class="my-3" />
<div>
<abp-button buttonType="submit" iconClass="fa fa-save" [disabled]="form.invalid">
Save
</abp-button>
</div>
</form>
```
**How it works:**
- The form contains main fields (`userName`, `email`) and a nested `FormGroup` (`profile`).
- The `profile` group includes `firstName` and `lastName` fields, each with their own validation rules.
- Validation rules are defined directly in the form builder.
- Error messages and validation feedback are handled automatically by ngx-validate and ABP Angular UI, just like with dynamic forms.
- This structure ensures that validation works automatically for both the main form and nested groups.
> **Note:** This approach is ideal for custom forms or when you want full control over the form structure. It provides a user experience and validation behavior similar to ABP's dynamic forms, but with manual control over the form layout and logic.
---

17
docs/en/modules/cms-kit/index.md

@ -72,6 +72,23 @@ CMS kit packages are designed for various usage scenarios. If you check the [CMS
- `Volo.CmsKit.Public.*` packages contain the functionalities used in public websites where users read blog posts or leave comments. - `Volo.CmsKit.Public.*` packages contain the functionalities used in public websites where users read blog posts or leave comments.
- `Volo.CmsKit.*` (without Admin/Public suffix) packages are called as unified packages. Unified packages are shortcuts for adding Admin & Public packages (of the related layer) separately. If you have a single application for administration and public web site, you can use these packages. - `Volo.CmsKit.*` (without Admin/Public suffix) packages are called as unified packages. Unified packages are shortcuts for adding Admin & Public packages (of the related layer) separately. If you have a single application for administration and public web site, you can use these packages.
## Integrating Public and Admin Packages in a Unified Application
If you are using a single application for both admin and public web site, it's important to configure the global layout settings appropriately. By default, the layout is set for a **Public Website**, which is suitable for public-facing pages. However, when your application serves both admin and public pages, you should explicitly set the global layout for all CMS Kit pages.
To do this, add a `_ViewStart.cshtml` file to your web project at `/Pages/Public/CmsKit/_ViewStart.cshtml` and configure the layout as shown below:
```html
@using Volo.Abp.AspNetCore.Mvc.UI.Theming
@inject IThemeManager ThemeManager
@{
// default: GetPublicLayout()
Layout = ThemeManager.CurrentTheme.GetApplicationLayout();
}
```
> The `_ViewStart.cshtml` file is used to set the layout for all pages in the `CmsKit` folder.
## Internals ## Internals
### Table / collection prefix & schema ### Table / collection prefix & schema

5
docs/en/modules/docs.md

@ -148,11 +148,6 @@ An ABP module must declare `[DependsOn]` attribute if it has a dependency upon a
{ {
options.DefinitionProviders.Add<MyProjectPermissionDefinitionProvider>(); options.DefinitionProviders.Add<MyProjectPermissionDefinitionProvider>();
}); });
Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<MyProjectApplicationAutoMapperProfile>();
});
} }
} }
``` ```

2
docs/en/others/why-abp-platform.md

@ -169,7 +169,7 @@ The learning curve is much lower than not using the ABP. That may sound surprisi
ABP creates a full stack, production-ready, working solution for you in seconds. Many of the real-life problems are already solved and many fine tune configurations are already applied for the ASP.NET Core and the other used libraries. If you start from scratch, you will experience and learn all these details yourself to truly implement your solution. ABP creates a full stack, production-ready, working solution for you in seconds. Many of the real-life problems are already solved and many fine tune configurations are already applied for the ASP.NET Core and the other used libraries. If you start from scratch, you will experience and learn all these details yourself to truly implement your solution.
ABP uses the industry standard frameworks, libraries and systems you already know (or need to learn to build a real-world product) like Angular, Blazor, MAUI, EF Core, AutoMapper, OpenIddict, Bootstrap, Redis, SignalR... etc. So, all your knowledge is directly re-usable with the ABP. ABP even simplifies using these libraries and systems and solves the integration problems. If you don't know these tools now, learning them will be easier within the ABP. ABP uses the industry standard frameworks, libraries and systems you already know (or need to learn to build a real-world product) like Angular, Blazor, MAUI, EF Core, AutoMapper (switched to Mapperly due to licensing concerns), OpenIddict, Bootstrap, Redis, SignalR... etc. So, all your knowledge is directly re-usable with the ABP. ABP even simplifies using these libraries and systems and solves the integration problems. If you don't know these tools now, learning them will be easier within the ABP.
ABP provides an excellent infrastructure to apply DDD principles and other best practices. It provides a lot of sweet abstractions and automation to reduce the repeating code. However, it doesn't force you to use or apply all these. A common mistake is to see that ABP has a lot of features, and it is hard to learn all of them. Having a lot of features is an advantage when you come to the point that you need them. However, you don't need to know a feature until you need it, and you can continue with the development approach you are used to. You can still write code as you are used to as if ABP doesn't provide all these benefits. Learning the ABP infrastructure is progressive. You will love it whenever you learn a new feature but can continue developing without knowing its existence. ABP provides an excellent infrastructure to apply DDD principles and other best practices. It provides a lot of sweet abstractions and automation to reduce the repeating code. However, it doesn't force you to use or apply all these. A common mistake is to see that ABP has a lot of features, and it is hard to learn all of them. Having a lot of features is an advantage when you come to the point that you need them. However, you don't need to know a feature until you need it, and you can continue with the development approach you are used to. You can still write code as you are used to as if ABP doesn't provide all these benefits. Learning the ABP infrastructure is progressive. You will love it whenever you learn a new feature but can continue developing without knowing its existence.

9
docs/en/release-info/migration-guides/pro/openiddict-microservice.md

@ -472,17 +472,12 @@ In `appsettings.json` replace **IdentityServer** section with **OpenIddict** and
typeof(AbpOpenIddictProWebModule), typeof(AbpOpenIddictProWebModule),
``` ```
- In **IdentityServiceWebModule.cs** add object mapping configurations: - In **IdentityServiceWebModule.cs** add object mapping configurations for [Mapperly](https://mapperly.riok.app/) (if you are using an another mapping providers, see the [Object to Object Mapping](../../../framework/infrastructure/object-to-object-mapping.md) documentation):
```csharp ```csharp
context.Services.AddAutoMapperObjectMapper<IdentityServiceWebModule>(); context.Services.AddMapperlyObjectMapper<IdentityServiceWebModule>();
Configure<AbpAutoMapperOptions>(options =>
{
options.AddMaps<IdentityServiceWebModule>(validate: true);
});
``` ```
### Shared Hosting Module ### Shared Hosting Module
- In **MyApplicationSharedHostingModule** replace the **database configuration**: - In **MyApplicationSharedHostingModule** replace the **database configuration**:

2
docs/en/solution-templates/guide.md

@ -27,7 +27,7 @@ Besides the overall solution structure, the internals of each project in a solut
### Library Integrations & Configurations ### Library Integrations & Configurations
When you use ABP startup solution templates to create a new solution, some **fundamental library installations** ([Serilog](https://serilog.net/), [Autofac](https://autofac.org/), [AutoMapper](https://automapper.org/), [Swagger](https://swagger.io/), [HealthCheck](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) and others..) and their fine-tuned configurations are already prepared for you. Also, required **[ABP packages](https://abp.io/packages)** are just installed based on your preferences and configured for **development and production environments**. When you use ABP startup solution templates to create a new solution, some **fundamental library installations** ([Serilog](https://serilog.net/), [Autofac](https://autofac.org/), [Mapperly](https://mapperly.riok.app/), [Swagger](https://swagger.io/), [HealthCheck](https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks) and others..) and their fine-tuned configurations are already prepared for you. Also, required **[ABP packages](https://abp.io/packages)** are just installed based on your preferences and configured for **development and production environments**.
### Development Ready ### Development Ready

47
docs/en/tutorials/book-store/part-01.md

@ -291,22 +291,17 @@ public class BookDto : AuditedEntityDto<Guid>
* The `BookDto` is used to transfer the book data to the presentation layer in order to show the book information on the UI. * The `BookDto` is used to transfer the book data to the presentation layer in order to show the book information on the UI.
* The `BookDto` is derived from the `AuditedEntityDto<Guid>` which has audit properties just like the `Book` entity defined above. * The `BookDto` is derived from the `AuditedEntityDto<Guid>` which has audit properties just like the `Book` entity defined above.
It will be needed to map the `Book` entities to the `BookDto` objects while returning books to the presentation layer. [AutoMapper](https://automapper.org) library can automate this conversion when you define the proper mapping. The startup template comes with AutoMapper pre-configured. So, you can just define the mapping in the `BookStoreApplicationAutoMapperProfile` class in the `Acme.BookStore.Application` project: It will be needed to map the `Book` entities to the `BookDto` objects while returning books to the presentation layer. [Mapperly](https://mapperly.riok.app/) library can automate this conversion when you define the proper mapping. The startup template comes with Mapperly pre-configured. So, you can just define the mapping in the `BookStoreApplicationMappers` class in the `Acme.BookStore.Application` project:
````csharp ```csharp
using Acme.BookStore.Books; [Mapper]
using AutoMapper; public partial class BookToBookDtoMapper : MapperBase<Book, BookDto>
namespace Acme.BookStore;
public class BookStoreApplicationAutoMapperProfile : Profile
{ {
public BookStoreApplicationAutoMapperProfile() public override partial BookDto Map(Book source);
{
CreateMap<Book, BookDto>(); public override partial void Map(Book source, BookDto destination);
}
} }
```` ```
> See the [object to object mapping](../../framework/infrastructure/object-to-object-mapping.md) document for details. > See the [object to object mapping](../../framework/infrastructure/object-to-object-mapping.md) document for details.
@ -343,21 +338,23 @@ public class CreateUpdateBookDto
As done to the `BookDto` above, we should define the mapping from the `CreateUpdateBookDto` object to the `Book` entity. The final class will be as shown below: As done to the `BookDto` above, we should define the mapping from the `CreateUpdateBookDto` object to the `Book` entity. The final class will be as shown below:
````csharp ```csharp
using Acme.BookStore.Books; [Mapper]
using AutoMapper; public partial class BookToBookDtoMapper : MapperBase<Book, BookDto>
{
public override partial BookDto Map(Book source);
namespace Acme.BookStore; public override partial void Map(Book source, BookDto destination);
}
public class BookStoreApplicationAutoMapperProfile : Profile [Mapper]
public partial class CreateUpdateBookDtoToBookMapper : MapperBase<CreateUpdateBookDto, Book>
{ {
public BookStoreApplicationAutoMapperProfile() public override partial Book Map(CreateUpdateBookDto source);
{
CreateMap<Book, BookDto>(); public override partial void Map(CreateUpdateBookDto source, Book destination);
CreateMap<CreateUpdateBookDto, Book>();
}
} }
```` ```
### IBookAppService ### IBookAppService
@ -416,7 +413,7 @@ public class BookAppService :
* `BookAppService` is derived from `CrudAppService<...>` which implements all the CRUD (create, read, update, delete) methods defined by the `ICrudAppService`. * `BookAppService` is derived from `CrudAppService<...>` which implements all the CRUD (create, read, update, delete) methods defined by the `ICrudAppService`.
* `BookAppService` injects `IRepository<Book, Guid>` which is the default repository for the `Book` entity. ABP automatically creates default repositories for each aggregate root (or entity). See the [repository document](../../framework/architecture/domain-driven-design/repositories.md). * `BookAppService` injects `IRepository<Book, Guid>` which is the default repository for the `Book` entity. ABP automatically creates default repositories for each aggregate root (or entity). See the [repository document](../../framework/architecture/domain-driven-design/repositories.md).
* `BookAppService` uses `IObjectMapper` service ([see](../../framework/infrastructure/object-to-object-mapping.md)) to map the `Book` objects to the `BookDto` objects and `CreateUpdateBookDto` objects to the `Book` objects. The Startup template uses the [AutoMapper](http://automapper.org/) library as the object mapping provider. We have defined the mappings before, so it will work as expected. * `BookAppService` uses `IObjectMapper` service ([see](../../framework/infrastructure/object-to-object-mapping.md)) to map the `Book` objects to the `BookDto` objects and `CreateUpdateBookDto` objects to the `Book` objects. The Startup template uses the [Mapperly](https://mapperly.riok.app/) library as the object mapping provider. We have defined the mappings before, so it will work as expected.
## Auto API Controllers ## Auto API Controllers

46
docs/en/tutorials/book-store/part-03.md

@ -298,23 +298,17 @@ public class EditModalModel : BookStorePageModel
### Mapping from BookDto to CreateUpdateBookDto ### Mapping from BookDto to CreateUpdateBookDto
To be able to map the `BookDto` to `CreateUpdateBookDto`, configure a new mapping. To do this, open the `BookStoreWebAutoMapperProfile.cs` file in the `Acme.BookStore.Web` project and change it as shown below: To be able to map the `BookDto` to `CreateUpdateBookDto`, configure a new mapping. To do this, open the `BookStoreWebMappers.cs` file in the `Acme.BookStore.Web` project and change it as shown below:
````csharp ```csharp
using AutoMapper; [Mapper]
public partial class BookDtoToCreateUpdateBookDtoMapper : MapperBase<BookDto, CreateUpdateBookDto>
namespace Acme.BookStore.Web;
public class BookStoreWebAutoMapperProfile : Profile
{ {
public BookStoreWebAutoMapperProfile() public override partial CreateUpdateBookDto Map(BookDto source);
{
CreateMap<BookDto, CreateUpdateBookDto>();
}
}
````
* We have just added `CreateMap<BookDto, CreateUpdateBookDto>();` to define this mapping. public override partial void Map(BookDto source, CreateUpdateBookDto destination);
}
```
> Notice that we do the mapping definition in the web layer as a best practice since it is only needed in this layer. > Notice that we do the mapping definition in the web layer as a best practice since it is only needed in this layer.
@ -1288,28 +1282,26 @@ We can now define a modal to edit the book. Add the following code to the end of
</Modal> </Modal>
```` ````
### AutoMapper Configuration ### Mapperly Configuration
The base `AbpCrudPageBase` uses the [object to object mapping](../../framework/infrastructure/object-to-object-mapping.md) system to convert an incoming `BookDto` object to a `CreateUpdateBookDto` object. So, we need to define the mapping. The base `AbpCrudPageBase` uses the [object to object mapping](../../framework/infrastructure/object-to-object-mapping.md) system to convert an incoming `BookDto` object to a `CreateUpdateBookDto` object. So, we need to define the mapping.
Open the `BookStoreBlazorAutoMapperProfile` inside the {{ if UI == "BlazorServer" }}`Acme.BookStore.Blazor` {{ else if UI == "MAUIBlazor" }}`Acme.BookStore.MauiBlazor` {{ else }}`Acme.BookStore.Blazor.Client`{{ end }} project and change the content as the following: Open the `BookStoreBlazorMappers` inside the {{ if UI == "BlazorServer" }}`Acme.BookStore.Blazor` {{ else if UI == "MAUIBlazor" }}`Acme.BookStore.MauiBlazor` {{ else }}`Acme.BookStore.Blazor.Client`{{ end }} project and change the content as the following:
````csharp ```csharp
using Acme.BookStore.Books; using Riok.Mapperly.Abstractions;
using AutoMapper; using Volo.Abp.Mapperly;
{{ if UI == "BlazorServer" }}namespace Acme.BookStore.Blazor; {{ else if UI == "MAUIBlazor" }}namespace Acme.BookStore.MauiBlazor; {{ else }}namespace Acme.BookStore.Blazor.Client;{{ end }} {{ if UI == "BlazorServer" }}namespace Acme.BookStore.Blazor; {{ else if UI == "MAUIBlazor" }}namespace Acme.BookStore.MauiBlazor; {{ else }}namespace Acme.BookStore.Blazor.Client;{{ end }}
public class BookStoreBlazorAutoMapperProfile : Profile [Mapper]
public partial class BookDtoToCreateUpdateBookDtoMapper : MapperBase<BookDto, CreateUpdateBookDto>
{ {
public BookStoreBlazorAutoMapperProfile() public override partial CreateUpdateBookDto Map(BookDto source);
{
CreateMap<BookDto, CreateUpdateBookDto>();
}
}
````
* We've just added the `CreateMap<BookDto, CreateUpdateBookDto>();` line to define the mapping. public override partial void Map(BookDto source, CreateUpdateBookDto destination);
}
```
### Test the Editing Modal ### Test the Editing Modal

14
docs/en/tutorials/book-store/part-08.md

@ -193,7 +193,7 @@ public async Task<AuthorDto> GetAsync(Guid id)
} }
```` ````
This method simply gets the `Author` entity by its `Id`, converts to the `AuthorDto` using the [object to object mapper](../../framework/infrastructure/object-to-object-mapping.md). This requires to configure the AutoMapper, which will be explained later. This method simply gets the `Author` entity by its `Id`, converts to the `AuthorDto` using the [object to object mapper](../../framework/infrastructure/object-to-object-mapping.md). This requires to configure the Mapperly, which will be explained later.
### GetListAsync ### GetListAsync
@ -350,12 +350,18 @@ Finally, add the following entries to the `Localization/BookStore/en.json` insid
## Object to Object Mapping ## Object to Object Mapping
`AuthorAppService` is using the `ObjectMapper` to convert the `Author` objects to `AuthorDto` objects. So, we need to define this mapping in the AutoMapper configuration. `AuthorAppService` is using the `ObjectMapper` to convert the `Author` objects to `AuthorDto` objects. So, we need to define this mapping in the Mapperly configuration.
Open the `BookStoreApplicationAutoMapperProfile` class inside the `Acme.BookStore.Application` project and add the following line to the constructor: Open the `BookStoreApplicationMappers` class inside the `Acme.BookStore.Application` project and define the following mapping class:
````csharp ````csharp
CreateMap<Author, AuthorDto>(); [Mapper]
public partial class AuthorToAuthorDtoMapper : MapperBase<Author, AuthorDto>
{
public override partial AuthorDto Map(Author source);
public override partial void Map(Author source, AuthorDto destination);
}
```` ````
## Data Seeder ## Data Seeder

74
docs/en/tutorials/book-store/part-09.md

@ -335,27 +335,16 @@ The main reason of this decision was to show you how to use a different model cl
* Added `[DataType(DataType.Date)]` attribute to the `BirthDate` which shows a date picker on the UI for this property. * Added `[DataType(DataType.Date)]` attribute to the `BirthDate` which shows a date picker on the UI for this property.
* Added `[TextArea]` attribute to the `ShortBio` which shows a multi-line text area instead of a standard textbox. * Added `[TextArea]` attribute to the `ShortBio` which shows a multi-line text area instead of a standard textbox.
In this way, you can specialize the view model class based on your UI requirements without touching to the DTO. As a result of this decision, we have used `ObjectMapper` to map `CreateAuthorViewModel` to `CreateAuthorDto`. To be able to do that, you need to add a new mapping code to the `BookStoreWebAutoMapperProfile` constructor: In this way, you can specialize the view model class based on your UI requirements without touching to the DTO. As a result of this decision, we have used `ObjectMapper` to map `CreateAuthorViewModel` to `CreateAuthorDto`. To be able to do that, you need to define a new mapping configuration in the `BookStoreWebMappers` class:
````csharp ```csharp
using Acme.BookStore.Authors; // ADDED NAMESPACE IMPORT [Mapper]
using Acme.BookStore.Books; public partial class CreateAuthorViewModelToCreateAuthorDtoMapper : MapperBase<Pages.Authors.CreateModalModel.CreateAuthorViewModel, CreateAuthorDto>
using AutoMapper;
namespace Acme.BookStore.Web;
public class BookStoreWebAutoMapperProfile : Profile
{ {
public BookStoreWebAutoMapperProfile() public override partial CreateAuthorDto Map(Pages.Authors.CreateModalModel.CreateAuthorViewModel source);
{ public override partial void Map(Pages.Authors.CreateModalModel.CreateAuthorViewModel source, CreateAuthorDto destination);
CreateMap<BookDto, CreateUpdateBookDto>();
// ADD a NEW MAPPING
CreateMap<Pages.Authors.CreateModalModel.CreateAuthorViewModel,
CreateAuthorDto>();
}
} }
```` ```
"New author" button will work as expected and open a new model when you run the application again: "New author" button will work as expected and open a new model when you run the application again:
@ -456,29 +445,22 @@ This class is similar to the `CreateModal.cshtml.cs` while there are some main d
* Uses the `IAuthorAppService.GetAsync(...)` method to get the editing author from the application layer. * Uses the `IAuthorAppService.GetAsync(...)` method to get the editing author from the application layer.
* `EditAuthorViewModel` has an additional `Id` property which is marked with the `[HiddenInput]` attribute that creates a hidden input for this property. * `EditAuthorViewModel` has an additional `Id` property which is marked with the `[HiddenInput]` attribute that creates a hidden input for this property.
This class requires to add two object mapping declarations to the `BookStoreWebAutoMapperProfile` class: This class requires to add two object mapping declarations, so open the `BookStoreWebMappers` class and add the following mappings:
```csharp ```csharp
using Acme.BookStore.Authors; [Mapper]
using Acme.BookStore.Books; public partial class AuthorDtoToEditAuthorViewModelMapper : MapperBase<AuthorDto, EditAuthorViewModel>
using AutoMapper;
namespace Acme.BookStore.Web;
public class BookStoreWebAutoMapperProfile : Profile
{ {
public BookStoreWebAutoMapperProfile() public override partial EditAuthorViewModel Map(AuthorDto source);
{
CreateMap<BookDto, CreateUpdateBookDto>();
CreateMap<Pages.Authors.CreateModalModel.CreateAuthorViewModel, public override partial void Map(AuthorDto source, EditAuthorViewModel destination);
CreateAuthorDto>(); }
// ADD THESE NEW MAPPINGS [Mapper]
CreateMap<AuthorDto, Pages.Authors.EditModalModel.EditAuthorViewModel>(); public partial class EditAuthorViewModelToUpdateAuthorDtoMapper : MapperBase<Pages.Authors.EditModalModel.EditAuthorViewModel, UpdateAuthorDto>
CreateMap<Pages.Authors.EditModalModel.EditAuthorViewModel, {
UpdateAuthorDto>(); public override partial UpdateAuthorDto Map(Pages.Authors.EditModalModel.EditAuthorViewModel source);
} public override partial void Map(Pages.Authors.EditModalModel.EditAuthorViewModel source, UpdateAuthorDto destination);
} }
``` ```
@ -1220,13 +1202,23 @@ This class typically defines the properties and methods used by the `Authors.raz
`Authors` class uses the `IObjectMapper` in the `OpenEditAuthorModal` method. So, we need to define this mapping. `Authors` class uses the `IObjectMapper` in the `OpenEditAuthorModal` method. So, we need to define this mapping.
Open the `BookStoreBlazorAutoMapperProfile.cs` in the {{ if UI == "BlazorServer" }}`Acme.BookStore.Blazor`{{ else if UI == "MAUIBlazor" }}`Acme.BookStore.MauiBlazor`{{ else }}`Acme.BookStore.Blazor.Client`{{ end }} project and add the following mapping code in the constructor: Open the `BookStoreBlazorMappers.cs` in the {{ if UI == "BlazorServer" }}`Acme.BookStore.Blazor`{{ else if UI == "MAUIBlazor" }}`Acme.BookStore.MauiBlazor`{{ else }}`Acme.BookStore.Blazor.Client`{{ end }} project and add the following mappings in the class:
````csharp ```csharp
CreateMap<AuthorDto, UpdateAuthorDto>(); using Riok.Mapperly.Abstractions;
```` using Volo.Abp.Mapperly;
using Acme.BookStore.Authors;
//...
[Mapper]
public partial class AuthorDtoToUpdateAuthorDtoMapper : MapperBase<AuthorDto, UpdateAuthorDto>
{
public override partial UpdateAuthorDto Map(AuthorDto source);
You will need to declare a `using Acme.BookStore.Authors;` statement to the beginning of the file. public override partial void Map(AuthorDto source, UpdateAuthorDto destination);
}
```
### Add to the Main Menu ### Add to the Main Menu

47
docs/en/tutorials/book-store/part-10.md

@ -578,11 +578,17 @@ Let's see the changes we've done:
### Object to Object Mapping Configuration ### Object to Object Mapping Configuration
Introduced the `AuthorLookupDto` class and used object mapping inside the `GetAuthorLookupAsync` method. So, we need to add a new mapping definition inside the `BookStoreApplicationAutoMapperProfile.cs` file of the `Acme.BookStore.Application` project: Introduced the `AuthorLookupDto` class and used object mapping inside the `GetAuthorLookupAsync` method. So, we need to add a new mapping definition inside the `BookStoreApplicationMappers.cs` file of the `Acme.BookStore.Application` project:
````csharp ```csharp
CreateMap<Author, AuthorLookupDto>(); [Mapper]
```` public partial class AuthorToAuthorLookupDtoMapper : MapperBase<Author, AuthorLookupDto>
{
public override partial AuthorLookupDto Map(Author source);
public override partial void Map(Author source, AuthorLookupDto destination);
}
```
## Unit Tests ## Unit Tests
@ -898,12 +904,37 @@ These changes require a small change in the `EditModal.cshtml`. Remove the `<abp
### Object to Object Mapping Configuration ### Object to Object Mapping Configuration
The changes above requires to define some object to object mappings. Open the `BookStoreWebAutoMapperProfile.cs` in the `Acme.BookStore.Web` project and add the following mapping definitions inside the constructor: The changes above requires to define some object to object mappings. Open the `BookStoreWebMappers.cs` in the `Acme.BookStore.Web` project and create the following mapping definitions:
```csharp ```csharp
CreateMap<Pages.Books.CreateModalModel.CreateBookViewModel, CreateUpdateBookDto>(); using Riok.Mapperly.Abstractions;
CreateMap<BookDto, Pages.Books.EditModalModel.EditBookViewModel>(); using Volo.Abp.Mapperly;
CreateMap<Pages.Books.EditModalModel.EditBookViewModel, CreateUpdateBookDto>();
//...
[Mapper]
public partial class CreateBookViewModelToCreateUpdateBookDtoMapper : MapperBase<Pages.Books.CreateModalModel.CreateBookViewModel, CreateUpdateBookDto>
{
public override partial CreateUpdateBookDto Map(Pages.Books.CreateModalModel.CreateBookViewModel source);
public override partial void Map(Pages.Books.CreateModalModel.CreateBookViewModel source, CreateUpdateBookDto destination);
}
[Mapper]
public partial class BookDtoToEditBookViewModelMapper : MapperBase<BookDto, Pages.Books.EditModalModel.EditBookViewModel>
{
public override partial Pages.Books.EditModalModel.EditBookViewModel Map(BookDto source);
public override partial void Map(BookDto source, Pages.Books.EditModalModel.EditBookViewModel destination);
}
[Mapper]
public partial class EditBookViewModelToCreateUpdateBookDtoMapper : MapperBase<Pages.Books.EditModalModel.EditBookViewModel, CreateUpdateBookDto>
{
public override partial CreateUpdateBookDto Map(Pages.Books.EditModalModel.EditBookViewModel source);
public override partial void Map(Pages.Books.EditModalModel.EditBookViewModel source, CreateUpdateBookDto destination);
}
``` ```
You can run the application and try to create a new book or update an existing book. You will see a drop down list on the create/update form to select the author of the book: You can run the application and try to create a new book or update an existing book. You will see a drop down list on the create/update form to select the author of the book:

17
docs/en/tutorials/microservice/part-05.md

@ -255,21 +255,20 @@ public class OrderAppService : ApplicationService, IOrderAppService
In this code snippet, we inject the `IRepository<Order, Guid>` into the `OrderAppService` class. We use this repository to interact with the `Order` entity. The `GetListAsync` method retrieves a list of orders from the database and maps them to the `OrderDto` class. The `CreateAsync` method creates a new order entity and inserts it into the database. In this code snippet, we inject the `IRepository<Order, Guid>` into the `OrderAppService` class. We use this repository to interact with the `Order` entity. The `GetListAsync` method retrieves a list of orders from the database and maps them to the `OrderDto` class. The `CreateAsync` method creates a new order entity and inserts it into the database.
Afterward, we need to configure the *AutoMapper* object to map the `Order` entity to the `OrderDto` class. Open the `OrderingServiceApplicationAutoMapperProfile` class in the `CloudCrm.OrderingService` project, located in the `ObjectMapping` folder, and add the following code: Afterward, we need to configure the *Mapperly* object to map the `Order` entity to the `OrderDto` class. Open the `OrderingServiceApplicationMappers` class in the `CloudCrm.OrderingService` project, located in the `ObjectMapping` folder, and add the following code:
```csharp ```csharp
using AutoMapper; using Riok.Mapperly.Abstractions;
using CloudCrm.OrderingService.Entities; using Volo.Abp.Mapperly;
using CloudCrm.OrderingService.Services;
namespace CloudCrm.OrderingService.ObjectMapping; namespace CloudCrm.OrderingService.ObjectMapping;
public class OrderingServiceApplicationAutoMapperProfile : Profile [Mapper]
public partial class OrderingServiceApplicationMappers : MapperBase<Order, OrderDto>
{ {
public OrderingServiceApplicationAutoMapperProfile() public override partial OrderDto Map(Order source);
{
CreateMap<Order, OrderDto>(); public override partial void Map(Order source, OrderDto destination);
}
} }
``` ```

22
docs/en/tutorials/microservice/part-06.md

@ -216,25 +216,25 @@ public class OrderDto
} }
``` ```
Lastly, open the `OrderingServiceApplicationAutoMapperProfile` class (the `OrderingServiceApplicationAutoMapperProfile.cs` file under the `ObjectMapping` folder of the `CloudCrm.OrderingService` project of the `CloudCrm.OrderingService` .NET solution) and ignore the `ProductName` property in the mapping configuration: Lastly, open the `OrderingServiceApplicationMappers` class (the `OrderingServiceApplicationMappers.cs` file under the `ObjectMapping` folder of the `CloudCrm.OrderingService` project of the `CloudCrm.OrderingService` .NET solution) and ignore the `ProductName` property in the mapping configuration:
```csharp ```csharp
using AutoMapper; using Riok.Mapperly.Abstractions;
using CloudCrm.OrderingService.Entities; using Volo.Abp.Mapperly;
using CloudCrm.OrderingService.Services;
using Volo.Abp.AutoMapper;
namespace CloudCrm.OrderingService.ObjectMapping; namespace CloudCrm.OrderingService.ObjectMapping;
public class OrderingServiceApplicationAutoMapperProfile : Profile [Mapper]
public partial class OrderingServiceApplicationMappers : MapperBase<Order, OrderDto>
{ {
public OrderingServiceApplicationAutoMapperProfile() [MapperIgnoreTarget(nameof(OrderDto.ProductName))]
{ public override partial OrderDto Map(Order source);
CreateMap<Order, OrderDto>()
.Ignore(x => x.ProductName); // New line [MapperIgnoreTarget(nameof(OrderDto.ProductName))]
} public override partial void Map(Order source, OrderDto destination);
} }
``` ```
Let's explain the changes we made: Let's explain the changes we made:
- We added a new property named `ProductName` to the `OrderDto` class. This property will hold the product name. - We added a new property named `ProductName` to the `OrderDto` class. This property will hold the product name.

22
docs/en/tutorials/modular-crm/part-03.md

@ -323,23 +323,17 @@ Notice that `ProductAppService` class implements the `IProductAppService` and al
#### Object Mapping #### Object Mapping
`ProductAppService.GetListAsync` method uses the `ObjectMapper` service to convert `Product` entities to `ProductDto` objects. The mapping should be configured. Open the `CatalogAutoMapperProfile` class in the `ModularCrm.Catalog` project and change it to the following code block: `ProductAppService.GetListAsync` method uses the `ObjectMapper` service to convert `Product` entities to `ProductDto` objects. The mapping should be configured. So, create a new mapping class in the `ModularCrm.Catalog` project that implements the `MapperBase<Product, ProductDto>` class with the `[Mapper]` attribute as follows:
````csharp ```csharp
using AutoMapper; [Mapper]
public partial class ProductToProductDtoMapper : MapperBase<Product, ProductDto>
namespace ModularCrm.Catalog;
public class CatalogAutoMapperProfile : Profile
{ {
public CatalogAutoMapperProfile() public override partial ProductDto Map(Product source);
{
CreateMap<Product, ProductDto>();
}
}
````
We've added the `CreateMap<Product, ProductDto>();` line to define the mapping. public override partial void Map(Product source, ProductDto destination);
}
```
### Exposing Application Services as HTTP API Controllers ### Exposing Application Services as HTTP API Controllers

20
docs/en/tutorials/modular-crm/part-05.md

@ -283,21 +283,17 @@ The new files under the `ModularCrm.Ordering.Contracts` project should be like t
### Implementing the Application Service ### Implementing the Application Service
First we configure the *AutoMapper* to map the `Order` entity to the `OrderDto` object, because we will need it later. Open the `OrderingAutoMapperProfile` under the `ModularCrm.Ordering` project: First, create a new mapping class (under the `ModularCrm.Ordering` project) that implements the `MapperBase<Order, OrderDto>` class with the `[Mapper]` attribute to map `Order` entities to `OrderDto` objects as follows, because we will need it later:
````csharp ```csharp
using AutoMapper; [Mapper]
public partial class OrderToOrderDtoMapper : MapperBase<Order, OrderDto>
namespace ModularCrm.Ordering;
public class OrderingAutoMapperProfile : Profile
{ {
public OrderingAutoMapperProfile() public override partial OrderDto Map(Order source);
{
CreateMap<Order, OrderDto>(); public override partial void Map(Order source, OrderDto destination);
}
} }
```` ```
Now, you can implement the `IOrderAppService` interface. Create an `OrderAppService` class under the `ModularCrm.Ordering` project: Now, you can implement the `IOrderAppService` interface. Create an `OrderAppService` class under the `ModularCrm.Ordering` project:

20
docs/en/tutorials/modular-crm/part-06.md

@ -217,21 +217,17 @@ public class OrderDto
} }
```` ````
Lastly, open the `OrderingAutoMapperProfile` class (the `OrderingAutoMapperProfile.cs` file under the `Services` folder of the `ModularCrm.Ordering` project of the `ModularCrm.Ordering` .NET solution) and ignore the `ProductName` property in the mapping configuration: Lastly, open the `OrderingApplicationMappers` class (the `OrderingApplicationMappers.cs` file under the `Services` folder of the `ModularCrm.Ordering` project of the `ModularCrm.Ordering` .NET solution) and add the following mapping class:
````csharp ````csharp
using AutoMapper; [Mapper]
using Volo.Abp.AutoMapper; public partial class OrderToOrderDtoMapper : MapperBase<Order, OrderDto>
namespace ModularCrm.Ordering;
public class OrderingApplicationAutoMapperProfile : Profile
{ {
public OrderingApplicationAutoMapperProfile() [MapperIgnoreTarget(nameof(OrderDto.ProductName))]
{ public override partial OrderDto Map(Order source);
CreateMap<Order, OrderDto>()
.Ignore(x => x.ProductName); // New line [MapperIgnoreTarget(nameof(OrderDto.ProductName))]
} public override partial void Map(Order source, OrderDto destination);
} }
```` ````

47
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/TelemetryApplicationMetricsEnricher.cs

@ -0,0 +1,47 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Internal.Telemetry.Activity;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Activity.Providers;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Reflection;
namespace Volo.Abp.AspNetCore.Mvc;
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>))]
public sealed class TelemetryApplicationMetricsEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>
{
private readonly ITypeFinder _typeFinder;
public TelemetryApplicationMetricsEnricher(ITypeFinder typeFinder, IServiceProvider serviceProvider) : base(serviceProvider)
{
_typeFinder = typeFinder;
}
protected override Task<bool> CanExecuteAsync(ActivityContext context)
{
return Task.FromResult(context.SessionType == SessionType.ApplicationRuntime);
}
protected override Task ExecuteAsync(ActivityContext context)
{
var appServiceCount = _typeFinder.Types.Count(t =>
typeof(IApplicationService).IsAssignableFrom(t) &&
t is { IsAbstract: false, IsInterface: false } &&
!t.AssemblyQualifiedName!.StartsWith(TelemetryConsts.VoloNameSpaceFilter));
var controllerCount = _typeFinder.Types.Count(t =>
typeof(ControllerBase).IsAssignableFrom(t) &&
!t.IsAbstract &&
!t.AssemblyQualifiedName!.StartsWith(TelemetryConsts.VoloNameSpaceFilter));
context.Current[ActivityPropertyNames.AppServiceCount] = appServiceCount;
context.Current[ActivityPropertyNames.ControllerCount] = controllerCount;
return Task.CompletedTask;
}
}

20
framework/src/Volo.Abp.Authorization.Abstractions/Properties/AssemblyInfo.cs

@ -0,0 +1,20 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Volo.Abp.Authorization.Abstractions")]
[assembly: AssemblyTrademark("")]
[assembly: InternalsVisibleTo("Volo.Abp.Authorization")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("83632bec-2f60-4c2b-b964-30e8b37fa9d8")]

2
framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionDefinition.cs

@ -108,6 +108,8 @@ public class PermissionDefinition :
Parent = this Parent = this
}; };
child[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName] = this[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName];
_children.Add(child); _children.Add(child);
return child; return child;

18
framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionDefinitionContext.cs

@ -11,6 +11,13 @@ public class PermissionDefinitionContext : IPermissionDefinitionContext
public Dictionary<string, PermissionGroupDefinition> Groups { get; } public Dictionary<string, PermissionGroupDefinition> Groups { get; }
internal IPermissionDefinitionProvider? CurrentProvider { get; set; }
public static class KnownPropertyNames
{
public const string CurrentProviderName = "_CurrentProviderName";
}
public PermissionDefinitionContext(IServiceProvider serviceProvider) public PermissionDefinitionContext(IServiceProvider serviceProvider)
{ {
ServiceProvider = serviceProvider; ServiceProvider = serviceProvider;
@ -28,7 +35,16 @@ public class PermissionDefinitionContext : IPermissionDefinitionContext
throw new AbpException($"There is already an existing permission group with name: {name}"); throw new AbpException($"There is already an existing permission group with name: {name}");
} }
return Groups[name] = new PermissionGroupDefinition(name, displayName); var group = new PermissionGroupDefinition(name, displayName);
if (CurrentProvider != null)
{
group[KnownPropertyNames.CurrentProviderName] = CurrentProvider.GetType().FullName;
}
Groups[name] = group;
return group;
} }
[NotNull] [NotNull]

2
framework/src/Volo.Abp.Authorization.Abstractions/Volo/Abp/Authorization/Permissions/PermissionGroupDefinition.cs

@ -61,6 +61,8 @@ public class PermissionGroupDefinition : ICanAddChildPermission
isEnabled isEnabled
); );
permission[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName] = this[PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName];
_permissions.Add(permission); _permissions.Add(permission);
return permission; return permission;

5
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/StaticPermissionDefinitionStore.cs

@ -84,18 +84,23 @@ public class StaticPermissionDefinitionStore : IStaticPermissionDefinitionStore,
foreach (var provider in providers) foreach (var provider in providers)
{ {
context.CurrentProvider = provider;
provider.PreDefine(context); provider.PreDefine(context);
} }
foreach (var provider in providers) foreach (var provider in providers)
{ {
context.CurrentProvider = provider;
provider.Define(context); provider.Define(context);
} }
foreach (var provider in providers) foreach (var provider in providers)
{ {
context.CurrentProvider = provider;
provider.PostDefine(context); provider.PostDefine(context);
} }
context.CurrentProvider = null;
return context.Groups; return context.Groups;
} }

45
framework/src/Volo.Abp.Authorization/Volo/Abp/Authorization/Permissions/TelemetryPermissionInfoEnricher.cs

@ -0,0 +1,45 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Activity.Providers;
using Volo.Abp.Internal.Telemetry.Constants;
namespace Volo.Abp.Authorization.Permissions;
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>))]
public sealed class TelemetryPermissionInfoEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>
{
private readonly IPermissionDefinitionManager _permissionDefinitionManager;
public TelemetryPermissionInfoEnricher(IPermissionDefinitionManager permissionDefinitionManager,
IServiceProvider serviceProvider) : base(serviceProvider)
{
_permissionDefinitionManager = permissionDefinitionManager;
}
protected override Task<bool> CanExecuteAsync(ActivityContext context)
{
return Task.FromResult(context.ProjectId.HasValue);
}
protected async override Task ExecuteAsync(ActivityContext context)
{
var permissions = await _permissionDefinitionManager.GetPermissionsAsync();
var userDefinedPermissionsCount = permissions.Count(IsUserDefinedPermission);
context.Current[ActivityPropertyNames.PermissionCount] = userDefinedPermissionsCount;
}
private static bool IsUserDefinedPermission(PermissionDefinition permission)
{
return permission.Properties.TryGetValue(PermissionDefinitionContext.KnownPropertyNames.CurrentProviderName, out var providerName) &&
providerName is string &&
!providerName.ToString()!.StartsWith(TelemetryConsts.VoloNameSpaceFilter);
}
}

1
framework/src/Volo.Abp.Core/Volo.Abp.Core.csproj

@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" /> <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" />
<PackageReference Include="Microsoft.Extensions.Options" /> <PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="System.Management" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" /> <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Logging" /> <PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" /> <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />

54
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationBase.cs

@ -4,13 +4,17 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations; using JetBrains.Annotations;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal; using Volo.Abp.Internal;
using Volo.Abp.Internal.Telemetry;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Logging; using Volo.Abp.Logging;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Threading;
namespace Volo.Abp; namespace Volo.Abp;
@ -149,6 +153,56 @@ public abstract class AbpApplicationBase : IAbpApplication
options.PlugInSources options.PlugInSources
); );
} }
protected void SetupTelemetryTracking()
{
if (!ShouldSendTelemetryData())
{
return;
}
AsyncHelper.RunSync(InitializeTelemetryTracking);
}
protected async Task SetupTelemetryTrackingAsync()
{
if (!ShouldSendTelemetryData())
{
return;
}
await InitializeTelemetryTracking();
}
private async Task InitializeTelemetryTracking()
{
try
{
using var scope = ServiceProvider.CreateScope();
var telemetryService = scope.ServiceProvider.GetRequiredService<ITelemetryService>();
await telemetryService.AddActivityAsync(ActivityNameConsts.ApplicationRun);
}
catch (Exception ex)
{
try
{
using var scope = ServiceProvider.CreateScope();
var logger = scope.ServiceProvider.GetRequiredService<ILogger<AbpApplicationBase>>();
logger.LogException(ex, LogLevel.Trace);
}
catch
{
/* ignored */
}
}
}
private bool ShouldSendTelemetryData()
{
using var scope = ServiceProvider.CreateScope();
var abpHostEnvironment = scope.ServiceProvider.GetRequiredService<IAbpHostEnvironment>();
var configuration = scope.ServiceProvider.GetRequiredService<IConfiguration>();
return abpHostEnvironment.IsDevelopment() && configuration.GetValue<bool?>("Abp:Telemetry:IsEnabled") == true;
}
//TODO: We can extract a new class for this //TODO: We can extract a new class for this
public virtual async Task ConfigureServicesAsync() public virtual async Task ConfigureServicesAsync()

4
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithExternalServiceProvider.cs

@ -44,6 +44,8 @@ internal class AbpApplicationWithExternalServiceProvider : AbpApplicationBase, I
SetServiceProvider(serviceProvider); SetServiceProvider(serviceProvider);
await InitializeModulesAsync(); await InitializeModulesAsync();
await SetupTelemetryTrackingAsync();
} }
public void Initialize([NotNull] IServiceProvider serviceProvider) public void Initialize([NotNull] IServiceProvider serviceProvider)
@ -53,6 +55,8 @@ internal class AbpApplicationWithExternalServiceProvider : AbpApplicationBase, I
SetServiceProvider(serviceProvider); SetServiceProvider(serviceProvider);
InitializeModules(); InitializeModules();
SetupTelemetryTracking();
} }
public override void Dispose() public override void Dispose()

3
framework/src/Volo.Abp.Core/Volo/Abp/AbpApplicationWithInternalServiceProvider.cs

@ -50,12 +50,15 @@ internal class AbpApplicationWithInternalServiceProvider : AbpApplicationBase, I
{ {
CreateServiceProvider(); CreateServiceProvider();
await InitializeModulesAsync(); await InitializeModulesAsync();
await SetupTelemetryTrackingAsync();
} }
public void Initialize() public void Initialize()
{ {
CreateServiceProvider(); CreateServiceProvider();
InitializeModules(); InitializeModules();
SetupTelemetryTracking();
} }
public override void Dispose() public override void Dispose()

13
framework/src/Volo.Abp.Core/Volo/Abp/DependencyInjection/ConventionalRegistrarBase.cs

@ -19,16 +19,15 @@ public abstract class ConventionalRegistrarBase : IConventionalRegistrar
{ {
types = AssemblyHelper types = AssemblyHelper
.GetAllTypes(assembly) .GetAllTypes(assembly)
.Where( .Where(type => type != null && type.IsClass && !type.IsAbstract && !type.IsGenericType)
type => type != null && .ToArray();
type.IsClass &&
!type.IsAbstract &&
!type.IsGenericType
).ToArray();
} }
catch (ReflectionTypeLoadException e) catch (ReflectionTypeLoadException e)
{ {
types = e.Types.Select(x => x!).ToArray(); types = e.Types
.Where(type => type != null && type.IsClass && !type.IsAbstract && !type.IsGenericType)
.Select(x => x!)
.ToArray();
logger.LogException(e); logger.LogException(e);
} }
catch (Exception e) catch (Exception e)

50
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityContext.cs

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
namespace Volo.Abp.Internal.Telemetry.Activity;
public class ActivityContext
{
public ActivityEvent Current { get; }
public Dictionary<string, object> ExtraProperties { get; } = new();
public bool IsTerminated { get; private set; }
public Guid? ProjectId => Current.Get<Guid?>(ActivityPropertyNames.ProjectId);
public Guid? SolutionId => Current.Get<Guid?>(ActivityPropertyNames.SolutionId);
public SessionType? SessionType => Current.Get<SessionType?>(ActivityPropertyNames.SessionType);
public string? DeviceId => Current.Get<string?>(ActivityPropertyNames.DeviceId);
public string? SolutionPath => ExtraProperties.TryGetValue(ActivityPropertyNames.SolutionPath, out var solutionPath)
? solutionPath?.ToString()
: null;
private ActivityContext(ActivityEvent current)
{
Current = current;
}
public static ActivityContext Create(string activityName, string? details = null,
Action<Dictionary<string, object>>? additionalProperties = null)
{
var activity = new ActivityEvent(activityName, details);
if (additionalProperties is not null)
{
var additionalPropertiesDict = new Dictionary<string, object>();
activity[ActivityPropertyNames.AdditionalProperties] = additionalPropertiesDict;
additionalProperties.Invoke(additionalPropertiesDict);
}
return new ActivityContext(activity);
}
public void Terminate()
{
IsTerminated = true;
}
}

147
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/ActivityEvent.cs

@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Volo.Abp.Internal.Telemetry.Constants;
namespace Volo.Abp.Internal.Telemetry.Activity;
public class ActivityEvent : Dictionary<string, object?>
{
public ActivityEvent()
{
this[ActivityPropertyNames.Id] = Guid.NewGuid();
this[ActivityPropertyNames.Time] = DateTimeOffset.UtcNow;
}
public ActivityEvent(string activityName, string? details = null) : this()
{
Check.NotNullOrWhiteSpace(activityName, nameof(activityName));
this[ActivityPropertyNames.ActivityName] = activityName;
this[ActivityPropertyNames.ActivityDetails] = details;
}
public bool HasSolutionInfo()
{
return this.ContainsKey(ActivityPropertyNames.HasSolutionInfo);
}
public bool HasDeviceInfo()
{
return this.ContainsKey(ActivityPropertyNames.HasDeviceInfo);
}
public bool HasProjectInfo()
{
return this.ContainsKey(ActivityPropertyNames.HasProjectInfo);
}
public T Get<T>(string key)
{
return TryConvert<T>(key, out var value) ? value : default!;
}
public bool TryGetValue<T>(string key, out T value)
{
return TryConvert(key, out value);
}
private bool TryConvert<T>(string key, out T result)
{
result = default!;
if (!this.TryGetValue(key, out var value) || value is null)
{
return false;
}
try
{
if (value is T tValue)
{
result = tValue;
return true;
}
if (value is JsonElement jsonElement)
{
value = ExtractFromJsonElement(jsonElement);
if (value is null)
{
return false;
}
}
var targetType = typeof(T);
var underlyingType = Nullable.GetUnderlyingType(targetType) ?? targetType;
if (underlyingType.IsEnum)
{
if (value is string str)
{
result = (T)Enum.Parse(underlyingType, str, ignoreCase: true);
}
else if (value is int intValue)
{
result = (T)Enum.ToObject(underlyingType, intValue);
}
return true;
}
if (underlyingType == typeof(Dictionary<string, object>[]))
{
result = (T)value;
return true;
}
if (underlyingType == typeof(Guid))
{
result = (T)(object)Guid.Parse(value.ToString()!);
return true;
}
if (underlyingType == typeof(DateTimeOffset))
{
result = (T)(object)DateTimeOffset.Parse(value.ToString()!);
return true;
}
// Nullable types
result = (T)Convert.ChangeType(value, underlyingType);
return true;
}
catch
{
return false;
}
}
private static object? ExtractFromJsonElement(JsonElement element)
{
return element.ValueKind switch
{
JsonValueKind.String => element.GetString(),
JsonValueKind.Number => element.GetInt32(),
JsonValueKind.True => true,
JsonValueKind.False => false,
JsonValueKind.Null => null,
JsonValueKind.Array => element.EnumerateArray()
.Select(item =>
{
if (item.ValueKind == JsonValueKind.Object)
{
return item.EnumerateObject()
.ToDictionary(prop => prop.Name, prop => ExtractFromJsonElement(prop.Value));
}
return new Dictionary<string, object?> { { "value", ExtractFromJsonElement(item) } };
})
.ToArray(),
JsonValueKind.Object => element.EnumerateObject()
.ToDictionary(prop => prop.Name, prop => ExtractFromJsonElement(prop.Value)),
_ => element.ToString()
};
}
}

7
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/IHasParentTelemetryActivityEventEnricher.cs

@ -0,0 +1,7 @@
using Volo.Abp.Internal.Telemetry.Activity.Providers;
namespace Volo.Abp.Internal.Telemetry.Activity.Contracts;
public interface IHasParentTelemetryActivityEventEnricher<out TParent> where TParent: TelemetryActivityEventEnricher
{
}

8
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/ITelemetryActivityEventBuilder.cs

@ -0,0 +1,8 @@
using System.Threading.Tasks;
namespace Volo.Abp.Internal.Telemetry.Activity.Contracts;
public interface ITelemetryActivityEventBuilder
{
Task<ActivityEvent?> BuildAsync(ActivityContext context);
}

11
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/ITelemetryActivityEventEnricher.cs

@ -0,0 +1,11 @@
using System.Threading.Tasks;
namespace Volo.Abp.Internal.Telemetry.Activity.Contracts;
public interface ITelemetryActivityEventEnricher
{
int ExecutionOrder { get; }
Task EnrichAsync(ActivityContext context);
}

17
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Contracts/ITelemetryActivityStorage.cs

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.Internal.Telemetry.Activity.Contracts;
public interface ITelemetryActivityStorage
{
Guid InitializeOrGetSession();
void DeleteActivities(ActivityEvent[] activities);
void SaveActivity(ActivityEvent activityEvent);
List<ActivityEvent> GetActivities();
bool ShouldAddDeviceInfo();
bool ShouldAddSolutionInformation(Guid solutionId);
bool ShouldAddProjectInfo(Guid projectId);
bool ShouldSendActivities();
void MarkActivitiesAsFailed(ActivityEvent[] activities);
}

49
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryActivityEventBuilder.cs

@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
public class TelemetryActivityEventBuilder : ITelemetryActivityEventBuilder, ISingletonDependency
{
private readonly List<ITelemetryActivityEventEnricher> _activityEnrichers;
public TelemetryActivityEventBuilder(IEnumerable<ITelemetryActivityEventEnricher> activityDataEnrichers)
{
_activityEnrichers = activityDataEnrichers
.Where(FilterEnricher)
.OrderByDescending(x => x.ExecutionOrder)
.ToList();
}
public virtual async Task<ActivityEvent?> BuildAsync(ActivityContext context)
{
foreach (var enricher in _activityEnrichers)
{
try
{
await enricher.EnrichAsync(context);
}
catch
{
//ignored
}
if (context.IsTerminated)
{
return null;
}
}
return context.Current;
}
private static bool FilterEnricher(ITelemetryActivityEventEnricher enricher)
{
return ProxyHelper.GetUnProxiedType(enricher).Assembly.FullName!.StartsWith(TelemetryConsts.VoloNameSpaceFilter) &&
enricher is not IHasParentTelemetryActivityEventEnricher<TelemetryActivityEventEnricher>;
}
}

70
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryActivityEventEnricher.cs

@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Abp.DynamicProxy;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
public abstract class TelemetryActivityEventEnricher : ITelemetryActivityEventEnricher, IScopedDependency
{
public virtual int ExecutionOrder { get; set; } = 0;
protected bool IgnoreChildren { get; set; }
protected virtual Type? ReplaceParentType { get; set; }
private readonly IServiceProvider _serviceProvider;
protected TelemetryActivityEventEnricher(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public async Task EnrichAsync(ActivityContext context)
{
if (!await CanExecuteAsync(context))
{
return;
}
await ExecuteAsync(context);
await ExecuteChildrenAsync(context);
}
protected virtual Task<bool> CanExecuteAsync(ActivityContext context)
{
return Task.FromResult(true);
}
protected abstract Task ExecuteAsync(ActivityContext context);
protected virtual async Task ExecuteChildrenAsync(ActivityContext context)
{
if (IgnoreChildren)
{
return;
}
using var scope = _serviceProvider.CreateScope();
foreach (var child in GetChildren(scope.ServiceProvider))
{
await child.EnrichAsync(context);
}
}
private ITelemetryActivityEventEnricher[] GetChildren(IServiceProvider serviceProvider)
{
var targetType = ReplaceParentType ?? ProxyHelper.GetUnProxiedType(this);
var genericInterfaceType = typeof(IHasParentTelemetryActivityEventEnricher<>).MakeGenericType(targetType);
var enumerableType = typeof(IEnumerable<>).MakeGenericType(genericInterfaceType);
var childServices = (IEnumerable<object>)serviceProvider.GetRequiredService(enumerableType);
return childServices
.Cast<ITelemetryActivityEventEnricher>()
.ToArray();
}
}

104
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryApplicationInfoEnricher.cs

@ -0,0 +1,104 @@
using System;
using System.IO;
using System.Reflection;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.Helpers;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetrySessionInfoEnricher>))]
public sealed class TelemetryApplicationInfoEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetrySessionInfoEnricher>
{
private readonly ITelemetryActivityStorage _telemetryActivityStorage;
public TelemetryApplicationInfoEnricher(ITelemetryActivityStorage telemetryActivityStorage, IServiceProvider serviceProvider) : base(serviceProvider)
{
_telemetryActivityStorage = telemetryActivityStorage;
}
protected override Task<bool> CanExecuteAsync(ActivityContext context)
{
return Task.FromResult(context.SessionType == SessionType.ApplicationRuntime);
}
protected override Task ExecuteAsync(ActivityContext context)
{
try
{
var entryAssembly = Assembly.GetEntryAssembly();
if (entryAssembly is null)
{
context.Terminate();
return Task.CompletedTask;
}
var projectMetaData = AbpProjectMetadataReader.ReadProjectMetadata(entryAssembly);
if (projectMetaData?.ProjectId == null || projectMetaData.AbpSlnPath.IsNullOrEmpty())
{
context.Terminate();
return Task.CompletedTask;
}
if (!_telemetryActivityStorage.ShouldAddProjectInfo(projectMetaData.ProjectId.Value))
{
IgnoreChildren = true;
return Task.CompletedTask;
}
var solutionId = ReadSolutionIdFromSolutionPath(projectMetaData.AbpSlnPath);
if (!solutionId.HasValue)
{
IgnoreChildren = true;
context.Terminate();
return Task.CompletedTask;
}
context.ExtraProperties[ActivityPropertyNames.SolutionPath] = projectMetaData.AbpSlnPath;
context.Current[ActivityPropertyNames.ProjectType] = projectMetaData.Role ?? string.Empty;
context.Current[ActivityPropertyNames.ProjectId] = projectMetaData.ProjectId.Value;
context.Current[ActivityPropertyNames.SolutionId] = solutionId;
context.Current[ActivityPropertyNames.HasProjectInfo] = true;
}
catch
{
//ignored
}
return Task.CompletedTask;
}
private static Guid? ReadSolutionIdFromSolutionPath(string solutionPath)
{
try
{
if (solutionPath.IsNullOrEmpty())
{
return null;
}
using var fs = new FileStream(solutionPath!, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var doc = JsonDocument.Parse(fs, new JsonDocumentOptions
{
AllowTrailingCommas = true
});
if (doc.RootElement.TryGetProperty("id", out var property) && property.TryGetGuid(out var solutionId))
{
return solutionId;
}
}
catch
{
// ignored
}
return null;
}
}

79
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryDeviceInfoEnricher.cs

@ -0,0 +1,79 @@
using System;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
[ExposeServices(typeof(ITelemetryActivityEventEnricher))]
internal sealed class TelemetryDeviceInfoEnricher : TelemetryActivityEventEnricher
{
private readonly ITelemetryActivityStorage _telemetryActivityStorage;
private readonly ISoftwareInfoProvider _softwareInfoProvider;
public TelemetryDeviceInfoEnricher(ITelemetryActivityStorage telemetryActivityStorage,
ISoftwareInfoProvider softwareInfoProvider, IServiceProvider serviceProvider) : base(serviceProvider)
{
_telemetryActivityStorage = telemetryActivityStorage;
_softwareInfoProvider = softwareInfoProvider;
}
protected async override Task ExecuteAsync(ActivityContext context)
{
try
{
var deviceId = DeviceManager.GetUniquePhysicalKey(true);
context.Current[ActivityPropertyNames.DeviceId] = deviceId;
if (!_telemetryActivityStorage.ShouldAddDeviceInfo())
{
return;
}
var softwareList = await _softwareInfoProvider.GetSoftwareInfoAsync();
context.Current[ActivityPropertyNames.InstalledSoftwares] = softwareList;
context.Current[ActivityPropertyNames.DeviceLanguage] = CultureInfo.CurrentUICulture.Name;
context.Current[ActivityPropertyNames.OperatingSystem] = GetOperatingSystem();
context.Current[ActivityPropertyNames.CountryIsoCode] = GetCountry();
context.Current[ActivityPropertyNames.HasDeviceInfo] = true;
context.Current[ActivityPropertyNames.OperatingSystemArchitecture] = RuntimeInformation.OSArchitecture.ToString();
}
catch
{
//ignored
}
}
private static OperationSystem GetOperatingSystem()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return OperationSystem.Windows;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return OperationSystem.Linux;
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return OperationSystem.MacOS;
}
return OperationSystem.Unknown;
}
private static string GetCountry()
{
var region = new RegionInfo(CultureInfo.InstalledUICulture.Name);
return region.TwoLetterISORegionName;
}
}

39
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetryModuleInfoEnricher.cs

@ -0,0 +1,39 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Modularity;
using Volo.Abp.Reflection;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>))]
internal sealed class TelemetryModuleInfoEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetryApplicationInfoEnricher>
{
private readonly IModuleContainer _moduleContainer;
private readonly IAssemblyFinder _assemblyFinder;
public TelemetryModuleInfoEnricher(IModuleContainer moduleContainer, IAssemblyFinder assemblyFinder,
IServiceProvider serviceProvider) : base(serviceProvider)
{
_moduleContainer = moduleContainer;
_assemblyFinder = assemblyFinder;
}
protected override Task<bool> CanExecuteAsync(ActivityContext context)
{
return Task.FromResult(context.SessionType == SessionType.ApplicationRuntime);
}
protected override Task ExecuteAsync(ActivityContext context)
{
context.Current[ActivityPropertyNames.ModuleCount] = _moduleContainer.Modules.Count;
context.Current[ActivityPropertyNames.ProjectCount] = _assemblyFinder.Assemblies.Count(x =>
!x.FullName.IsNullOrEmpty() &&
!x.FullName.StartsWith(TelemetryConsts.VoloNameSpaceFilter));
return Task.CompletedTask;
}
}

27
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetrySessionInfoEnricher.cs

@ -0,0 +1,27 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
[ExposeServices(typeof(ITelemetryActivityEventEnricher))]
public class TelemetrySessionInfoEnricher : TelemetryActivityEventEnricher
{
public override int ExecutionOrder { get; set; } = 10;
public TelemetrySessionInfoEnricher(IServiceProvider serviceProvider) : base(serviceProvider)
{
}
protected override Task ExecuteAsync(ActivityContext context)
{
context.Current[ActivityPropertyNames.SessionType] = SessionType.ApplicationRuntime;
context.Current[ActivityPropertyNames.SessionId] = Guid.NewGuid().ToString();
context.Current[ActivityPropertyNames.IsFirstSession] = !File.Exists(TelemetryPaths.ActivityStorage);
return Task.CompletedTask;
}
}

130
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Providers/TelemetrySolutionInfoEnricher.cs

@ -0,0 +1,130 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
namespace Volo.Abp.Internal.Telemetry.Activity.Providers;
[ExposeServices(typeof(ITelemetryActivityEventEnricher), typeof(IHasParentTelemetryActivityEventEnricher<TelemetrySessionInfoEnricher>))]
internal sealed class TelemetrySolutionInfoEnricher : TelemetryActivityEventEnricher, IHasParentTelemetryActivityEventEnricher<TelemetrySessionInfoEnricher>
{
private readonly ITelemetryActivityStorage _telemetryActivityStorage;
public TelemetrySolutionInfoEnricher(ITelemetryActivityStorage telemetryActivityStorage, IServiceProvider serviceProvider) : base(serviceProvider)
{
_telemetryActivityStorage = telemetryActivityStorage;
}
protected override Task<bool> CanExecuteAsync(ActivityContext context)
{
if (context.SolutionId.HasValue && !context.SolutionPath.IsNullOrEmpty())
{
return Task.FromResult(_telemetryActivityStorage.ShouldAddSolutionInformation(context.SolutionId.Value));
}
return Task.FromResult(false);
}
protected override Task ExecuteAsync(ActivityContext context)
{
try
{
var jsonContent = File.ReadAllText(context.SolutionPath!);
using var doc = JsonDocument.Parse(jsonContent, new JsonDocumentOptions
{
AllowTrailingCommas = true
});
var root = doc.RootElement;
if (root.TryGetProperty("creatingStudioConfiguration", out var creatingStudioConfiguration))
{
AddSolutionCreationConfiguration(context, creatingStudioConfiguration);
}
if (root.TryGetProperty("modules", out var modulesElement))
{
AddModuleInfo(context, modulesElement);
}
context.Current[ActivityPropertyNames.HasSolutionInfo] = true;
}
catch
{
//ignored
}
return Task.CompletedTask;
}
private static void AddSolutionCreationConfiguration(ActivityContext context, JsonElement config)
{
context.Current[ActivityPropertyNames.Template] = TelemetryJsonExtensions.GetStringOrNull(config, "template");
context.Current[ActivityPropertyNames.CreatedAbpStudioVersion] = TelemetryJsonExtensions.GetStringOrNull(config, "createdAbpStudioVersion");
context.Current[ActivityPropertyNames.MultiTenancy] = TelemetryJsonExtensions.GetBooleanOrNull(config, "multiTenancy");
context.Current[ActivityPropertyNames.UiFramework] = TelemetryJsonExtensions.GetStringOrNull(config, "uiFramework");
context.Current[ActivityPropertyNames.DatabaseProvider] = TelemetryJsonExtensions.GetStringOrNull(config, "databaseProvider");
context.Current[ActivityPropertyNames.Theme] = TelemetryJsonExtensions.GetStringOrNull(config, "theme");
context.Current[ActivityPropertyNames.ThemeStyle] = TelemetryJsonExtensions.GetStringOrNull(config, "themeStyle");
context.Current[ActivityPropertyNames.HasPublicWebsite] = TelemetryJsonExtensions.GetBooleanOrNull(config, "publicWebsite");
context.Current[ActivityPropertyNames.IsTiered] = TelemetryJsonExtensions.GetBooleanOrNull(config, "tiered");
context.Current[ActivityPropertyNames.SocialLogins] = TelemetryJsonExtensions.GetBooleanOrNull(config, "socialLogin");
context.Current[ActivityPropertyNames.DatabaseManagementSystem] = TelemetryJsonExtensions.GetStringOrNull(config, "databaseManagementSystem");
context.Current[ActivityPropertyNames.IsSeparateTenantSchema] = TelemetryJsonExtensions.GetBooleanOrNull(config, "separateTenantSchema");
context.Current[ActivityPropertyNames.MobileFramework] = TelemetryJsonExtensions.GetStringOrNull(config, "mobileFramework");
context.Current[ActivityPropertyNames.IncludeTests] = TelemetryJsonExtensions.GetBooleanOrNull(config, "includeTests");
context.Current[ActivityPropertyNames.DynamicLocalization] = TelemetryJsonExtensions.GetBooleanOrNull(config, "dynamicLocalization");
context.Current[ActivityPropertyNames.KubernetesConfiguration] = TelemetryJsonExtensions.GetBooleanOrNull(config, "kubernetesConfiguration");
context.Current[ActivityPropertyNames.GrafanaDashboard] = TelemetryJsonExtensions.GetBooleanOrNull(config, "grafanaDashboard");
}
private static void AddModuleInfo(ActivityContext context, JsonElement modulesElement)
{
var modules = new List<Dictionary<string, object?>>();
foreach (var module in modulesElement.EnumerateObject())
{
var modulePath = GetModuleFilePath(context.SolutionPath!, module);
if (modulePath.IsNullOrEmpty())
{
continue;
}
var moduleJsonFileContent = File.ReadAllText(modulePath);
using var moduleDoc = JsonDocument.Parse(moduleJsonFileContent);
if (!moduleDoc.RootElement.TryGetProperty("imports", out var imports))
{
continue;
}
foreach (var import in imports.EnumerateObject())
{
modules.Add(new Dictionary<string, object?>
{
{ ActivityPropertyNames.ModuleName, import.Name },
{ ActivityPropertyNames.ModuleVersion, TelemetryJsonExtensions.GetStringOrNull(import.Value, "version") },
{ ActivityPropertyNames.ModuleInstallationTime, TelemetryJsonExtensions.GetDateTimeOffsetOrNull(import.Value, "creationTime") }
});
}
}
context.Current[ActivityPropertyNames.InstalledModules] = modules;
}
private static string? GetModuleFilePath(string solutionPath, JsonProperty module)
{
var path = TelemetryJsonExtensions.GetStringOrNull(module.Value, "path");
if (path.IsNullOrEmpty())
{
return null;
}
var fullPath = Path.Combine(Path.GetDirectoryName(solutionPath)!, path);
return File.Exists(fullPath) ? fullPath : null;
}
}

18
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/FailedActivityInfo.cs

@ -0,0 +1,18 @@
using System;
namespace Volo.Abp.Internal.Telemetry.Activity.Storage;
internal class FailedActivityInfo
{
public DateTimeOffset FirstFailTime { get; set; }
public DateTimeOffset LastFailTime { get; set; }
public int RetryCount { get; set; }
public bool IsExpired()
{
var now = DateTimeOffset.UtcNow;
return RetryCount >= TelemetryPeriod.MaxActivityRetryCount ||
now - FirstFailTime > TelemetryPeriod.MaxFailedActivityAge;
}
}

207
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/TelemetryActivityStorage.cs

@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.Activity.Contracts;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Helpers;
namespace Volo.Abp.Internal.Telemetry.Activity.Storage;
public class TelemetryActivityStorage : ITelemetryActivityStorage, ISingletonDependency
{
private TelemetryActivityStorageState State { get; }
private readonly static JsonSerializerOptions JsonSerializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
public TelemetryActivityStorage()
{
CreateDirectoryIfNotExist();
State = LoadState();
}
public void SaveActivity(ActivityEvent activityEvent)
{
State.Activities.Add(activityEvent);
var activityName = activityEvent.Get<string>(ActivityPropertyNames.ActivityName);
if (activityName == ActivityNameConsts.AbpStudioClose)
{
State.SessionId = null;
}
if (activityEvent.HasDeviceInfo())
{
State.LastDeviceInfoAddTime = DateTimeOffset.UtcNow;
}
if (activityEvent.HasSolutionInfo())
{
var solutionId = activityEvent.Get<Guid>(ActivityPropertyNames.SolutionId);
State.Solutions[solutionId] = DateTimeOffset.UtcNow;
}
if (activityEvent.HasProjectInfo())
{
var projectId = activityEvent.Get<Guid>(ActivityPropertyNames.ProjectId);
State.Projects[projectId] = DateTimeOffset.UtcNow;
}
SaveState();
}
public List<ActivityEvent> GetActivities()
{
return State.Activities;
}
public Guid InitializeOrGetSession()
{
if (State.SessionId.HasValue)
{
return State.SessionId.Value;
}
State.SessionId = Guid.NewGuid();
SaveState();
return State.SessionId.Value;
}
public void DeleteActivities(ActivityEvent[] activities)
{
var activityIds = new HashSet<Guid>(activities.Select(x => x.Get<Guid>(ActivityPropertyNames.Id)));
State.Activities.RemoveAll(x => activityIds.Contains(x.Get<Guid>(ActivityPropertyNames.Id)));
SaveState();
}
public void MarkActivitiesAsFailed(ActivityEvent[] activities)
{
var now = DateTimeOffset.UtcNow;
foreach (var activity in activities)
{
var activityId = activity.Get<Guid>(ActivityPropertyNames.Id);
if (State.FailedActivities.TryGetValue(activityId, out var failedActivityInfo))
{
failedActivityInfo.RetryCount++;
failedActivityInfo.LastFailTime = now;
if (!failedActivityInfo.IsExpired())
{
continue;
}
State.Activities.RemoveAll(x=> x.Get<Guid>(ActivityPropertyNames.Id) == activityId);
State.FailedActivities.Remove(activityId);
}
else
{
State.FailedActivities[activityId] = new FailedActivityInfo
{
FirstFailTime = now,
LastFailTime = now,
RetryCount = 1
};
}
}
SaveState();
}
public bool ShouldAddDeviceInfo()
{
return State.LastDeviceInfoAddTime is null ||
DateTimeOffset.UtcNow - State.LastDeviceInfoAddTime > TelemetryPeriod.InformationSendPeriod;
}
public bool ShouldAddSolutionInformation(Guid solutionId)
{
return !State.Solutions.TryGetValue(solutionId, out var lastSend) ||
DateTimeOffset.UtcNow - lastSend > TelemetryPeriod.InformationSendPeriod;
}
public bool ShouldAddProjectInfo(Guid projectId)
{
return !State.Projects.TryGetValue(projectId, out var lastSend) ||
DateTimeOffset.UtcNow - lastSend > TelemetryPeriod.InformationSendPeriod;
}
public bool ShouldSendActivities()
{
return State.ActivitySendTime is null ||
DateTimeOffset.UtcNow - State.ActivitySendTime > TelemetryPeriod.ActivitySendPeriod;
}
private void SaveState()
{
try
{
var json = JsonSerializer.Serialize(State, JsonSerializerOptions);
var encryptedJson = Cryptography.Encrypt(json);
File.WriteAllText(TelemetryPaths.ActivityStorage, encryptedJson, Encoding.UTF8);
}
catch
{
// Ignored
}
}
private static TelemetryActivityStorageState LoadState()
{
try
{
if (!File.Exists(TelemetryPaths.ActivityStorage))
{
return new TelemetryActivityStorageState();
}
var fileContent = MutexExecutor.ReadFileSafely(TelemetryPaths.ActivityStorage);
if (fileContent.IsNullOrEmpty())
{
return new TelemetryActivityStorageState();
}
var json = Cryptography.Decrypt(fileContent);
var state = JsonSerializer.Deserialize<TelemetryActivityStorageState>(json, JsonSerializerOptions)!;
state.Activities = state.Activities.Where(x => x != null).ToList();
return state;
}
catch
{
return new TelemetryActivityStorageState();
}
}
private static void CreateDirectoryIfNotExist()
{
try
{
var storageDirectory = Path.GetDirectoryName(TelemetryPaths.ActivityStorage)!;
if (!Directory.Exists(storageDirectory))
{
Directory.CreateDirectory(storageDirectory);
}
}
catch
{
// Ignored
}
}
}

16
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/TelemetryActivityStorageState.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
namespace Volo.Abp.Internal.Telemetry.Activity.Storage;
internal class TelemetryActivityStorageState
{
public DateTimeOffset? ActivitySendTime { get; set; }
public DateTimeOffset? LastDeviceInfoAddTime { get; set; }
public Guid? SessionId { get; set; }
public List<ActivityEvent> Activities { get; set; } = new();
public Dictionary<Guid,DateTimeOffset> Solutions { get; set; } = new();
public Dictionary<Guid, DateTimeOffset> Projects { get; set; } = new();
public Dictionary<Guid, FailedActivityInfo> FailedActivities { get; set; } = new();
}

34
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/Storage/TelemetryPeriod.cs

@ -0,0 +1,34 @@
using System;
namespace Volo.Abp.Internal.Telemetry.Activity.Storage;
static internal class TelemetryPeriod
{
private const string TestModeEnvironmentVariable = "ABP_TELEMETRY_TEST_MODE";
static TelemetryPeriod()
{
var isTestMode = IsTestModeEnabled();
InformationSendPeriod = isTestMode
? TimeSpan.FromSeconds(15)
: TimeSpan.FromDays(7);
ActivitySendPeriod = isTestMode
? TimeSpan.FromSeconds(5)
: TimeSpan.FromDays(1);
}
public static TimeSpan ActivitySendPeriod { get; }
public static TimeSpan InformationSendPeriod { get; }
public static int MaxActivityRetryCount { get; set; } = 3;
public static TimeSpan MaxFailedActivityAge { get; set; } = TimeSpan.FromDays(30);
private static bool IsTestModeEnabled()
{
var testModeVariable =
Environment.GetEnvironmentVariable(TestModeEnvironmentVariable, EnvironmentVariableTarget.User);
return bool.TryParse(testModeVariable, out var isTestMode) && isTestMode;
}
}

34
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Activity/TelemetryJsonExtensions.cs

@ -0,0 +1,34 @@
using System;
using System.Text.Json;
namespace Volo.Abp.Internal.Telemetry.Activity;
static internal class TelemetryJsonExtensions
{
static internal string? GetStringOrNull(JsonElement element, string propertyName)
{
return element.TryGetProperty(propertyName, out var property)
? property.GetString() ?? null
: null;
}
static internal bool? GetBooleanOrNull(JsonElement element, string propertyName)
{
if (element.TryGetProperty(propertyName, out var property) && bool.TryParse(property.GetString(), out var boolValue))
{
return boolValue;
}
return null;
}
static internal DateTimeOffset? GetDateTimeOffsetOrNull(JsonElement element, string propertyName)
{
if (element.TryGetProperty(propertyName, out var date) && DateTimeOffset.TryParse(date.GetString(), out var dateTimeValue))
{
return dateTimeValue;
}
return null;
}
}

12
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/AbpPlatformUrls.cs

@ -0,0 +1,12 @@
namespace Volo.Abp.Internal.Telemetry.Constants;
public static class AbpPlatformUrls
{
#if DEBUG
public const string AbpTelemetryApiUrl = "https://localhost:44393/";
#else
public const string AbpTelemetryApiUrl = "https://telemetry.abp.io/";
#endif
}

76
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/ActivityNameConsts.cs

@ -0,0 +1,76 @@
namespace Volo.Abp.Internal.Telemetry.Constants;
public static class ActivityNameConsts
{
public const string AbpStudioOpen = "AbpStudio.Open";
public const string AbpStudioOpenFirstTimeForDevice = "AbpStudio.Open.FirstTimeForDevice";
public const string AbpStudioOpenFirstTimeForUser = "AbpStudio.Open.FirstTimeForUser";
public const string AbpStudioClose = "AbpStudio.Close";
public const string AbpStudioCloseWithoutLogin = "AbpStudio.Close.WithoutLogin";
public const string AbpStudioLogin = "AbpStudio.Login";
public const string AbpStudioCampaignClick = "AbpStudio.Campaing.Click";
public const string AbpStudioCommunityPostClick = "AbpStudio.CommunityPost.Click";
public const string AbpStudioSolutionInitExisting = "AbpStudio.Solution.InitExisting";
public const string AbpStudioSolutionNew = "AbpStudio.Solution.New";
public const string AbpStudioSolutionNewMicroservice = "AbpStudio.Solution.New.Microservice";
public const string AbpStudioSolutionAddModule = "AbpStudio.Solution.Add.Module";
public const string AbpStudioSolutionAddModuleEmpty = "AbpStudio.Solution.Add.Module.Empty";
public const string AbpStudioSolutionAddModuleDdd = "AbpStudio.Solution.Add.Module.Ddd";
public const string AbpStudioSolutionAddModuleStandard = "AbpStudio.Solution.Add.Module.Standard";
public const string AbpStudioSolutionAddMicroservice = "AbpStudio.Solution.Add.Microservice";
public const string AbpStudioSolutionAddGateway = "AbpStudio.Solution.Add.Gateway";
public const string AbpStudioSolutionAddWeb = "AbpStudio.Solution.Add.Web";
public const string AbpStudioSolutionAddPackage = "AbpStudio.Solution.Add.Package";
public const string AbpStudioSolutionAddPackageHttpApiLayer = "AbpStudio.Solution.Add.Package.HttpApiLayer";
public const string AbpStudioAbpCliInstallLibs = "AbpStudio.AbpCli.InstallLibs";
public const string AbpStudioAbpCliUpgradeAbp = "AbpStudio.AbpCli.UpgradeAbp";
public const string AbpStudioAbpCliSwitchToStable = "AbpStudio.AbpCli.SwitchToStable";
public const string AbpStudioAbpCliSwitchToPreview = "AbpStudio.AbpCli.SwitchToPreview";
public const string AbpStudioAbpCliSwitchToNightly = "AbpStudio.AbpCli.SwitchToNightly";
public const string AbpStudioAbpCliClean = "AbpStudio.AbpCli.Clean";
public const string AbpStudioDotnetCliBuild = "AbpStudio.DotnetCli.Build";
public const string AbpStudioDotnetCliGraphBuild = "AbpStudio.DotnetCli.GraphBuild";
public const string AbpStudioDotnetCliClean = "AbpStudio.DotnetCli.Clean";
public const string AbpStudioDotnetCliRestore = "AbpStudio.DotnetCli.Restore";
public const string AbpStudioSolutionRunnerRunApp = "AbpStudio.SolutionRunner.RunApp";
public const string AbpStudioSolutionRunnerAddCsharpApp = "AbpStudio.SolutionRunner.Add.CsharpApp";
public const string AbpStudioSolutionRunnerAddCliApp = "AbpStudio.SolutionRunner.Add.CliApp";
public const string AbpStudioSolutionRunnerAddProfile = "AbpStudio.SolutionRunner.Add.Profile";
public const string AbpStudioSolutionRunnerAppManageMetadata = "AbpStudio.SolutionRunner.App.Manage.Metadata";
public const string AbpStudioSolutionRunnerAppManageSecrets = "AbpStudio.SolutionRunner.App.Manage.Secrets";
public const string AbpStudioSolutionOpen = "AbpStudio.Solution.Open";
public const string AbpStudioMonitoringBrowse = "AbpStudio.Monitoring.Browse";
public const string AbpStudioMonitoringHttpRequests = "AbpStudio.Monitoring.HttpRequests";
public const string AbpStudioMonitoringHttpRequestsDetail = "AbpStudio.Monitoring.HttpRequests.Detail";
public const string AbpStudioMonitoringEvents = "AbpStudio.Monitoring.Events";
public const string AbpStudioMonitoringEventsDetail = "AbpStudio.Monitoring.Events.Detail";
public const string AbpStudioMonitoringExceptions = "AbpStudio.Monitoring.Exceptions";
public const string AbpStudioMonitoringExceptionsDetail = "AbpStudio.Monitoring.Exceptions.Detail";
public const string AbpStudioMonitoringLogs = "AbpStudio.Monitoring.Logs";
public const string AbpStudioKubernetesAddProfile = "AbpStudio.Kubernetes.Add.Profile";
public const string AbpStudioKubernetesConnect = "AbpStudio.Kubernetes.Connect";
public const string AbpStudioKubernetesIntercept = "AbpStudio.Kubernetes.Intercept";
public const string AbpStudioKubernetesHelmCommandsInstall = "AbpStudio.Kubernetes.Helm.Commands.Install";
public const string AbpStudioKubernetesHelmCommandsBuildImages = "AbpStudio.Kubernetes.Helm.Commands.BuildImages";
public const string AbpStudioKubernetesHelmChartsRefreshSubCharts = "AbpStudio.Kubernetes.Helm.Charts.RefreshSubCharts";
public const string AbpStudioKubernetesHelmChartsManageMetadata = "AbpStudio.Kubernetes.Helm.Charts.Manage.Metadata";
public const string AbpStudioLogsShow = "AbpStudio.Logs.Show";
public const string AbpStudioSuiteOpen = "AbpStudio.Suite.Open";
public const string AbpStudioGlobalSecretsManage = "AbpStudio.GlobalSecrets.Manage";
public const string AbpStudioGlobalMetadataManage = "AbpStudio.GlobalMetadata.Manage";
public const string AbpCliCommandsNewSolution = "AbpCli.Comands.NewSolution";
public const string AbpCliCommandsNewModule = "AbpCli.Comands.NewModule";
public const string AbpCliCommandsNewPackage = "AbpCli.Comands.NewPackage";
public const string AbpCliCommandsUpdate = "AbpCli.Comands.Update";
public const string AbpCliCommandsClean = "AbpCli.Comands.Clean";
public const string AbpCliCommandsAddPackage = "AbpCli.Comands.AddPackage";
public const string AbpCliCommandsAddPackageRef = "AbpCli.Comands.AddPackageRef";
public const string AbpCliCommandsInstallModule = "AbpCli.Comands.InstallModule";
public const string AbpCliCommandsInstallLocalModule = "AbpCli.Comands.InstallLocalModule";
public const string AbpCliCommandsListModules = "AbpCli.Comands.ListModules";
public const string AbpCliRun = "AbpCli.Run";
public const string AbpCliExit = "AbpCli.Exit";
public const string ApplicationRun = "Application.Run";
public const string AbpStudioBrowserOpen = "AbpStudio.Browser.Open";
public const string Error = "Error";
}

77
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/ActivityPropertyNames.cs

@ -0,0 +1,77 @@
namespace Volo.Abp.Internal.Telemetry.Constants;
public static class ActivityPropertyNames
{
public const string SessionId = "SessionId";
public const string ActivityName = "ActivityName";
public const string Error = "Error";
public const string ErrorDetail = "ErrorDetail";
public const string Id = "Id";
public const string UserId = "UserId";
public const string OrganizationId = "OrganizationId";
public const string IpAddress = "IpAddress";
public const string IsFirstSession = "IsFirstSession";
public const string DeviceId = "DeviceId";
public const string DeviceLanguage = "DeviceLanguage";
public const string OperatingSystem = "OperatingSystem";
public const string CountryIsoCode = "CountryIsoCode";
public const string InstalledSoftwares = "InstalledSoftwares";
public const string ControllerCount = "ControllerCount";
public const string EntityCount = "EntityCount";
public const string ProjectCount = "ProjectCount";
public const string ModuleCount = "ModuleCount";
public const string PermissionCount = "PermissionCount";
public const string AppServiceCount = "AppServiceCount";
public const string ProjectType = "ProjectType";
public const string ProjectId = "ProjectId";
public const string SolutionId = "SolutionId";
public const string Template = "Template";
public const string CreatedAbpStudioVersion = "CreatedAbpStudioVersion";
public const string IsTiered = "IsTiered";
public const string UiFramework = "UiFramework";
public const string DatabaseProvider = "DatabaseProvider";
public const string DatabaseManagementSystem = "DatabaseManagementSystem";
public const string IsSeparateTenantSchema = "IsSeparateTenantSchema";
public const string Theme = "Theme";
public const string ThemeStyle = "ThemeStyle";
public const string MobileFramework = "MobileFramework";
public const string HasPublicWebsite = "HasPublicWebsite";
public const string IncludeTests = "IncludeTests";
public const string MultiTenancy = "MultiTenancy";
public const string DynamicLocalization = "DynamicLocalization";
public const string KubernetesConfiguration = "KubernetesConfiguration";
public const string GrafanaDashboard = "GrafanaDashboard";
public const string SocialLogins = "SocialLogins";
public const string InstalledModules = "InstalledModules";
public const string SolutionPath = "SolutionPath";
public const string LicenseType = "LicenseType";
public const string SessionType = "SessionType";
public const string HasError = "HasError";
public const string ActivityDuration = "ActivityDuration";
public const string ActivityDetails = "ActivityDetails";
public const string Time = "Time";
public const string SoftwareName = "Name";
public const string SoftwareVersion = "Version";
public const string SoftwareUiTheme = "UiTheme";
public const string SoftwareType = "SoftwareType";
public const string WebFramework = "WebFramework";
public const string Dbms = "Dbms";
public const string UiTheme = "UiTheme";
public const string UiThemeStyle = "UiThemeStyle";
public const string MobileApp = "MobileApp";
public const string SampleCrudPage = "SampleCrudPage";
public const string FirstAbpVersion = "FirstAbpVersion";
public const string FirstDotnetVersion = "FirstDotnetVersion";
public const string CreationTool = "CreationTool";
public const string ModuleName = "ModuleName";
public const string ModuleVersion = "ModuleVersion";
public const string ModuleInstallationTime = "ModuleInstallationTime";
public const string ExtraProperties = "ExtraProperties";
public const string HasSolutionInfo = "HasSolutionInfo";
public const string HasDeviceInfo = "HasDeviceInfo";
public const string HasProjectInfo = "HasProjectInfo";
public const string ErrorMessage = "ErrorMessage";
public const string FailingActivity = "FailingActivity";
public const string OperatingSystemArchitecture = "OperatingSystemArchitecture";
public const string AdditionalProperties = "AdditionalProperties";
}

260
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/DeviceManager.cs

@ -0,0 +1,260 @@
using System;
namespace Volo.Abp.Internal.Telemetry.Constants;
static internal class DeviceManager
{
public static string GetUniquePhysicalKey(bool shouldHash)
{
char platformId = '?';
char osArchitecture = '?';
string operatingSystem = "?";
try
{
string osPrefix;
string uniqueKey;
platformId = GetPlatformIdOrDefault();
osArchitecture = GetOsArchitectureOrDefault();
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform
.Windows))
{
operatingSystem = "Windows";
uniqueKey = GetUniqueKeyForWindows();
osPrefix = "W";
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
.OSPlatform.Linux))
{
operatingSystem = "Linux";
uniqueKey = GetHarddiskSerialForLinux();
osPrefix = "L";
}
else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices
.OSPlatform.OSX)) //MAC
{
operatingSystem = "OSX";
uniqueKey = GetHarddiskSerialForOsX();
osPrefix = "O";
}
else
{
operatingSystem = "Other";
uniqueKey = GetNetworkAdapterSerial();
osPrefix = "X";
}
if (shouldHash)
{
uniqueKey = ConvertToMd5(uniqueKey).ToUpperInvariant();
}
return osPrefix + platformId + osArchitecture + "-" + uniqueKey;
}
catch
{
return Guid.NewGuid().ToString();
}
}
private static string GetNetworkAdapterSerial()
{
string macAddress = string.Empty;
var networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
foreach (var networkInterface in networkInterfaces)
{
if (networkInterface.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Loopback)
{
continue;
}
var physicalAddress = networkInterface.GetPhysicalAddress().ToString();
if (string.IsNullOrEmpty(physicalAddress))
{
continue;
}
macAddress = physicalAddress;
break;
}
return macAddress!;
}
private static char GetPlatformIdOrDefault(char defaultValue = '*')
{
try
{
return ((int)System.Environment.OSVersion.Platform).ToString()[0];
}
catch
{
return defaultValue;
}
}
private static string ConvertToMd5(string text)
{
using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
{
return EncodeBase64(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text)));
}
}
private static string EncodeBase64(byte[] ba)
{
var hex = new System.Text.StringBuilder(ba.Length * 2);
foreach (var b in ba)
{
hex.AppendFormat("{0:x2}", b);
}
return hex.ToString();
}
private static char GetOsArchitectureOrDefault(char defaultValue = '*')
{
try
{
return ((int)System.Runtime.InteropServices.RuntimeInformation.OSArchitecture).ToString()[0];
}
catch
{
return defaultValue;
}
}
private static string GetUniqueKeyForWindows()
{
try
{
return GetProcessorIdForWindows();
}
catch
{
}
return GetWindowsMachineUniqueId();
}
private static string GetProcessorIdForWindows()
{
using (var managementObjectSearcher =
new System.Management.ManagementObjectSearcher("SELECT ProcessorId FROM Win32_Processor"))
{
using (var searcherObj = managementObjectSearcher.Get())
{
if (searcherObj.Count == 0)
{
throw new System.Exception("No unique computer ID found for this computer!");
}
var managementObjectEnumerator = searcherObj.GetEnumerator();
managementObjectEnumerator.MoveNext();
return managementObjectEnumerator.Current.GetPropertyValue("ProcessorId").ToString()!;
}
}
}
private static string GetWindowsMachineUniqueId()
{
return RunCommandAndGetOutput("powershell (Get-CimInstance -Class Win32_ComputerSystemProduct).UUID");
}
private static string GetHarddiskSerialForLinux()
{
return RunCommandAndGetOutput(
"udevadm info --query=all --name=/dev/sda | grep ID_SERIAL_SHORT | tr -d \"ID_SERIAL_SHORT=:\"");
}
private static string GetHarddiskSerialForOsX()
{
var command =
"ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, \"\\\"\"); printf(\"%s\\n\", line[4]); }'";
command = System.Text.RegularExpressions.Regex.Replace(command, @"(\\*)" + "\"", @"$1$1\" + "\"");
return RunCommandAndGetOutput(command);
}
private static string RunCommandAndGetOutput(string command)
{
var output = "";
using (var process = new System.Diagnostics.Process())
{
process.StartInfo = new System.Diagnostics.ProcessStartInfo(GetFileName())
{
Arguments = GetArguments(command),
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
};
process.Start();
process?.WaitForExit();
using (var stdOut = process!.StandardOutput)
{
using (var stdErr = process.StandardError)
{
output = stdOut.ReadToEnd();
output += stdErr.ReadToEnd();
}
}
}
return output.Trim();
}
private static string GetFileName()
{
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
System.Runtime.InteropServices.OSPlatform.OSX) ||
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform
.Linux))
{
string[] fileNames = { "/bin/bash", "/usr/bin/bash", "/bin/sh", "/usr/bin/sh" };
foreach (var fileName in fileNames)
{
try
{
if (System.IO.File.Exists(fileName))
{
return fileName;
}
}
catch
{
//ignore
}
}
return "/bin/bash";
}
//Windows default.
return "cmd.exe";
}
private static string GetArguments(string command)
{
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(
System.Runtime.InteropServices.OSPlatform.OSX) ||
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform
.Linux))
{
return "-c \"" + command + "\"";
}
//Windows default.
return "/C \"" + command + "\"";
}
}

9
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/AbpTool.cs

@ -0,0 +1,9 @@
namespace Volo.Abp.Internal.Telemetry.Constants.Enums;
public enum AbpTool : byte
{
Unknown = 0,
StudioUI = 1,
StudioCli = 2,
OldCli = 3
}

9
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/OperationSystem.cs

@ -0,0 +1,9 @@
namespace Volo.Abp.Internal.Telemetry.Constants.Enums;
public enum OperationSystem
{
Unknown = 0,
Windows = 1,
MacOS = 2,
Linux = 3,
}

9
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/SessionType.cs

@ -0,0 +1,9 @@
namespace Volo.Abp.Internal.Telemetry.Constants.Enums;
public enum SessionType
{
Unknown = 0,
AbpStudio = 1,
AbpCli = 2,
ApplicationRuntime = 3
}

11
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/Enums/SoftwareType.cs

@ -0,0 +1,11 @@
namespace Volo.Abp.Internal.Telemetry.Constants.Enums;
public enum SoftwareType : byte
{
Others = 0,
AbpStudio = 1,
DotnetSdk = 2,
OperatingSystem = 3,
Ide = 4,
Browser = 5
}

6
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/TelemetryConsts.cs

@ -0,0 +1,6 @@
namespace Volo.Abp.Internal.Telemetry.Constants;
public class TelemetryConsts
{
public const string VoloNameSpaceFilter = "Volo.";
}

13
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Constants/TelemetryPaths.cs

@ -0,0 +1,13 @@
using System;
using System.IO;
namespace Volo.Abp.Internal.Telemetry.Constants;
public static class TelemetryPaths
{
public static string AccessToken => Path.Combine(AbpRootPath, "cli", "access-token.bin");
public static string ComputerId => Path.Combine(AbpRootPath, "cli", "computer-id.bin");
public static string ActivityStorage => Path.Combine(AbpRootPath , "telemetry", "activity-storage.bin");
public static string Studio => Path.Combine(AbpRootPath, "studio");
private readonly static string AbpRootPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".abp");
}

9
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Contracts/ISoftwareDetector.cs

@ -0,0 +1,9 @@
using System.Threading.Tasks;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
internal interface ISoftwareDetector
{
string Name { get; }
Task<SoftwareInfo?> DetectAsync();
}

9
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Contracts/ISoftwareInfoProvider.cs

@ -0,0 +1,9 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
internal interface ISoftwareInfoProvider
{
Task<List<SoftwareInfo>> GetSoftwareInfoAsync();
}

11
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Contracts/SoftwareInfo.cs

@ -0,0 +1,11 @@
using Volo.Abp.Internal.Telemetry.Constants.Enums;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
internal class SoftwareInfo(string name, string? version, string? uiTheme, SoftwareType softwareType)
{
public string Name { get; set; } = name;
public string? Version { get; set; } = version;
public string? UiTheme { get; set; } = uiTheme;
public SoftwareType SoftwareType { get; set; } = softwareType;
}

78
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Core/SoftwareDetector.cs

@ -0,0 +1,78 @@
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
[ExposeServices(typeof(ISoftwareDetector))]
abstract internal class SoftwareDetector: ISoftwareDetector , ISingletonDependency
{
public abstract string Name { get; }
public abstract Task<SoftwareInfo?> DetectAsync();
protected virtual async Task<string?> ExecuteCommandAsync(string command, string? arg)
{
var outputBuilder = new StringBuilder();
var processStartInfo = new ProcessStartInfo
{
FileName = command,
Arguments = arg ?? "",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
using var process = new Process();
process.StartInfo = processStartInfo;
process.EnableRaisingEvents = true;
var tcs = new TaskCompletionSource<bool>();
process.OutputDataReceived += (sender, e) =>
{
if (e.Data != null)
{
outputBuilder.AppendLine(e.Data);
}
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null)
{
outputBuilder.AppendLine(e.Data);
}
};
process.Exited += (sender, e) =>
{
tcs.TrySetResult(true);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
await tcs.Task;
var output = outputBuilder.ToString().Trim();
return string.IsNullOrWhiteSpace(output) ? null : output;
}
protected string? GetFileVersion(string filePath)
{
try
{
var versionInfo = FileVersionInfo.GetVersionInfo(filePath);
return versionInfo.FileVersion;
}
catch
{
return string.Empty;
}
}
}

76
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/AbpStudioDetector.cs

@ -0,0 +1,76 @@
using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class AbpStudioDetector : SoftwareDetector
{
public override string Name => "Abp Studio";
private const string AbpStudioVersionExtensionName = "Volo.Abp.Studio.Extensions.StandardSolutionTemplates";
public override Task<SoftwareInfo?> DetectAsync()
{
try
{
var uiTheme = GetAbpStudioUiTheme();
var version = GetAbpStudioVersion();
return Task.FromResult<SoftwareInfo?>(new SoftwareInfo(Name, version, uiTheme, SoftwareType.AbpStudio));
}
catch
{
return Task.FromResult<SoftwareInfo?>(null);
}
}
private string? GetAbpStudioUiTheme()
{
var ideStateJsonPath = Path.Combine(
TelemetryPaths.Studio,
"ui",
"ide-state.json"
);
if (!File.Exists(ideStateJsonPath))
{
return null;
}
using var fs = new FileStream(ideStateJsonPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var doc = JsonDocument.Parse(fs);
return doc.RootElement.TryGetProperty("theme", out var themeElement) ? themeElement.GetString() : null;
}
private string? GetAbpStudioVersion()
{
var extensionsFilePath = Path.Combine(TelemetryPaths.Studio, "extensions.json");
if (!File.Exists(extensionsFilePath))
{
return null;
}
using var fs = new FileStream(extensionsFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using var doc = JsonDocument.Parse(fs);
if (doc.RootElement.TryGetProperty("Extensions", out var extensionsElement) &&
extensionsElement.ValueKind == JsonValueKind.Array)
{
foreach (var extension in extensionsElement.EnumerateArray())
{
if (extension.TryGetProperty("name", out var nameProp) &&
nameProp.GetString() == AbpStudioVersionExtensionName &&
extension.TryGetProperty("version", out var versionProp))
{
return versionProp.GetString();
}
}
}
return null;
}
}

48
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/ChromeDetector.cs

@ -0,0 +1,48 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class ChromeDetector : SoftwareDetector
{
public override string Name => "Chrome";
public async override Task<SoftwareInfo?> DetectAsync()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var chromePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Google", "Chrome", "Application", "chrome.exe");
if (File.Exists(chromePath))
{
return new SoftwareInfo(Name, GetFileVersion(chromePath), null, SoftwareType.Browser);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var chromePath = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome";
if (File.Exists(chromePath))
{
var version = await ExecuteCommandAsync(chromePath, "--version");
return new SoftwareInfo(Name, version, null, SoftwareType.Browser);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var chromePath = "/usr/bin/google-chrome";
if (File.Exists(chromePath))
{
var version = await ExecuteCommandAsync(chromePath, "--version");
return new SoftwareInfo(Name, version, null, SoftwareType.Browser);
}
}
return null;
}
}

17
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/DotnetSdkDetector.cs

@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class DotnetSdkDetector : SoftwareDetector
{
public override string Name => "DotnetSdk";
public async override Task<SoftwareInfo?> DetectAsync()
{
return new SoftwareInfo(Name, Environment.Version.ToString(), null, SoftwareType.DotnetSdk);
}
}

45
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/FireFoxDetector.cs

@ -0,0 +1,45 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class FireFoxDetector : SoftwareDetector
{
public override string Name => "Firefox";
public async override Task<SoftwareInfo?> DetectAsync()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var firefoxPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Mozilla Firefox", "firefox.exe");
if (File.Exists(firefoxPath))
{
return new SoftwareInfo(Name, GetFileVersion(firefoxPath), null, SoftwareType.Browser);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var firefoxPath = "/Applications/Firefox.app/Contents/MacOS/firefox";
if (File.Exists(firefoxPath))
{
var version = await ExecuteCommandAsync(firefoxPath, "--version");
return new SoftwareInfo(Name, version, null, SoftwareType.Browser);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var firefoxPath = "/usr/bin/firefox";
if (File.Exists(firefoxPath))
{
var version = await ExecuteCommandAsync(firefoxPath, "--version");
return new SoftwareInfo(Name, version, null, SoftwareType.Browser);
}
}
return null;
}
}

47
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/MsEdgeDetector.cs

@ -0,0 +1,47 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class MsEdgeDetector : SoftwareDetector
{
public override string Name => "MsEdge";
public async override Task<SoftwareInfo?> DetectAsync()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var firefoxPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
"Microsoft", "Edge", "Application", "msedge.exe");
if (File.Exists(firefoxPath))
{
return new SoftwareInfo(Name, GetFileVersion(firefoxPath), null, SoftwareType.Browser);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var edgePath = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge";
if (File.Exists(edgePath))
{
var version = await ExecuteCommandAsync(edgePath, "--version");
return new SoftwareInfo(Name, version, null, SoftwareType.Browser);
}
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var edgePath = "/usr/bin/microsoft-edge";
if (File.Exists(edgePath))
{
var version = await ExecuteCommandAsync(edgePath, "--version");
return new SoftwareInfo(Name, version, null, SoftwareType.Browser);
}
}
return null;
}
}

33
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/NodeJsDetector.cs

@ -0,0 +1,33 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal class NodeJsDetector : SoftwareDetector
{
public override string Name => "Node.js";
public async override Task<SoftwareInfo?> DetectAsync()
{
try
{
var output = await ExecuteCommandAsync("node", "-v");
if (output.IsNullOrWhiteSpace())
{
return null;
}
var version = output.Trim().TrimStart('v');
return new SoftwareInfo(Name, version, uiTheme: null, SoftwareType.Others);
}
catch
{
return null;
}
}
}

77
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/OperatingSystemDetector.cs

@ -0,0 +1,77 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class OperatingSystemDetector : SoftwareDetector
{
public override string Name => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Windows" :
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? "macOS" : "Linux";
public async override Task<SoftwareInfo?> DetectAsync()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return new SoftwareInfo(Name, Environment.OSVersion.Version.ToString(), null, SoftwareType.OperatingSystem);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var version = await ExecuteCommandAsync("sw_vers", "-productVersion");
return new SoftwareInfo(Name, version, GetMacUiTheme(), SoftwareType.OperatingSystem);
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var version = await ExecuteCommandAsync("lsb_release", "-ds") ?? await ExecuteCommandAsync("uname", "-r");
return new SoftwareInfo(Name, version, await GetLinuxUiTheme(), SoftwareType.OperatingSystem);
}
return null;
}
private async Task<string?> GetLinuxUiTheme()
{
var output = await ExecuteCommandAsync("gsettings", "get org.gnome.desktop.interface gtk-theme");
if (!output.IsNullOrWhiteSpace() && output.ToLowerInvariant().Contains("dark"))
{
return "Dark";
}
return "Light";
}
private string? GetMacUiTheme()
{
try
{
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = "defaults",
Arguments = "read -g AppleInterfaceStyle",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true
};
process.Start();
var output = process.StandardOutput.ReadToEnd().Trim();
process.WaitForExit();
return output == "Dark" ? "Dark" : "Light";
}
catch
{
return "Light";
}
}
}

100
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/RiderDetector.cs

@ -0,0 +1,100 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Xml.Linq;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class RiderDetector : SoftwareDetector
{
public override string Name => "Rider";
public override Task<SoftwareInfo?> DetectAsync()
{
try
{
string baseConfigDir;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
baseConfigDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"JetBrains");
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
baseConfigDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"Library", "Application Support", "JetBrains");
}
else
{
baseConfigDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
".config", "JetBrains");
}
if (!Directory.Exists(baseConfigDir))
{
return Task.FromResult<SoftwareInfo?>(null);
}
var riderDirs = Directory
.GetDirectories(baseConfigDir, "Rider*")
.Select(dir =>
{
var name = Path.GetFileName(dir);
var verStr = name.Substring("Rider".Length);
return Version.TryParse(verStr, out var v)
? (Path: dir, Version: v)
: (Path: null, Version: null);
})
.Where(x => x.Path != null)
.ToList();
if (!riderDirs.Any())
{
return Task.FromResult<SoftwareInfo?>(null);
}
var latest = riderDirs
.OrderByDescending(x => x.Version)
.First();
var theme = string.Empty;
var colorsFile = Path.Combine(latest.Path!, "options", "colors.scheme.xml");
if (File.Exists(colorsFile))
{
try
{
var doc = XDocument.Load(colorsFile);
var schemeEl = doc
.Descendants("global_color_scheme")
.FirstOrDefault();
var schemeName = schemeEl?.Attribute("name")?.Value;
if (!schemeName.IsNullOrEmpty())
{
theme = schemeName.IndexOf("dark", StringComparison.OrdinalIgnoreCase) >= 0
? "Dark"
: "Light";
}
}
catch
{
//ignored
}
}
return Task.FromResult<SoftwareInfo?>(new SoftwareInfo(Name, latest.Version?.ToString(), theme,
SoftwareType.Ide));
}
catch (Exception e)
{
return Task.FromResult<SoftwareInfo?>(null);
}
}
}

132
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/VisualStudioCodeDetector.cs

@ -0,0 +1,132 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.Json;
using System.Threading.Tasks;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class VisualStudioCodeDetector : SoftwareDetector
{
public override string Name => "Visual Studio Code";
public async override Task<SoftwareInfo?> DetectAsync()
{
string? installDir = null;
string? settingsPath = null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var progFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
var candidates = new[]
{
Path.Combine(localAppData, "Programs", "Microsoft VS Code"),
Path.Combine(progFiles, "Microsoft VS Code")
};
installDir = candidates.FirstOrDefault(Directory.Exists);
settingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Code", "User", "globalStorage" ,"storage.json"
);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
var app = "/Applications/Visual Studio Code.app";
if (Directory.Exists(app))
{
installDir = app;
}
settingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
"Library", "Application Support", "Code", "User", "globalStorage", "storage.json"
);
}
else
{
var candidate = "/usr/share/code";
if (Directory.Exists(candidate))
{
installDir = candidate;
}
settingsPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
".config", "Code", "User", "globalStorage", "storage.json"
);
}
if (installDir == null)
{
return null;
}
Version? version = null;
var productJson = RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
? Path.Combine(installDir, "Contents", "Resources", "app", "product.json")
: Path.Combine(installDir, "resources", "app", "product.json");
if (File.Exists(productJson))
{
try
{
using var jsonDoc = JsonDocument.Parse(File.ReadAllText(productJson));
var root = jsonDoc.RootElement;
if (root.TryGetProperty("version", out var versionProp))
{
var versionStr = versionProp.GetString();
if (Version.TryParse(versionStr, out var v))
{
version = v;
}
}
}
catch
{
}
}
if (version == null)
{
return null;
}
var theme = "Unknown";
if (File.Exists(settingsPath))
{
try
{
using var json = JsonDocument.Parse( File.ReadAllText(settingsPath));
var root = json.RootElement;
if (root.TryGetProperty("theme", out var themeProp))
{
var themeName = themeProp.GetString() ?? "";
if (themeName.IndexOf("dark", StringComparison.OrdinalIgnoreCase) >= 0)
{
theme = "Dark";
}
else if (themeName.IndexOf("light", StringComparison.OrdinalIgnoreCase) >= 0)
{
theme = "Light";
}
}
}
catch
{
// ignored
}
}
return new SoftwareInfo(Name, version?.ToString(), theme, SoftwareType.Ide);
}
}

106
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Detectors/VisualStudioDetector.cs

@ -0,0 +1,106 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Volo.Abp.Internal.Telemetry.Constants.Enums;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Core;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Detectors;
internal sealed class VisualStudioDetector : SoftwareDetector
{
public override string Name => "Visual Studio";
public override Task<SoftwareInfo?> DetectAsync()
{
var version = GetVisualStudioVersionViaVsWhere();
var theme = GetVisualStudioTheme();
if (version == null)
{
return Task.FromResult<SoftwareInfo?>(null);
}
return Task.FromResult<SoftwareInfo?>(new SoftwareInfo(
name: Name,
version: version,
uiTheme: theme,
softwareType: SoftwareType.Ide));
}
private string? GetVisualStudioVersionViaVsWhere()
{
var vswherePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
"Microsoft Visual Studio",
"Installer",
"vswhere.exe");
if (!File.Exists(vswherePath))
{
return null;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = vswherePath,
Arguments = "-latest -property catalog_productDisplayVersion",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
var output = process.StandardOutput.ReadToEnd().Trim();
process.WaitForExit();
return string.IsNullOrWhiteSpace(output) ? null : output;
}
private string? GetVisualStudioTheme()
{
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var vsSettingsDir = Path.Combine(localAppData, "Microsoft", "VisualStudio");
if (!Directory.Exists(vsSettingsDir))
{
return null;
}
var settingsPath = Directory.GetFiles(vsSettingsDir, "CurrentSettings*.vssettings", SearchOption.AllDirectories)
.OrderByDescending(File.GetLastWriteTime)
.FirstOrDefault();
if (string.IsNullOrEmpty(settingsPath))
{
return null;
}
try
{
var doc = XDocument.Load(settingsPath);
var themeId = doc.Descendants("Theme")
.FirstOrDefault()?.Attribute("Id")?.Value;
return themeId?.ToUpperInvariant() switch
{
"{1DED0138-47CE-435E-84EF-9EC1F439B749}" => "Dark",
"{DE3DBBCD-F642-433C-8353-8F1DF4370ABA}" => "Light",
"{2DED0138-47CE-435E-84EF-9EC1F439B749}" => "Blue",
_ => "Unknown"
};
}
catch
{
return null;
}
}
}

40
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/EnvironmentInspection/Providers/SoftwareInfoProvider.cs

@ -0,0 +1,40 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Internal.Telemetry.EnvironmentInspection.Contracts;
namespace Volo.Abp.Internal.Telemetry.EnvironmentInspection.Providers;
internal class SoftwareInfoProvider : ISoftwareInfoProvider , ISingletonDependency
{
private readonly IEnumerable<ISoftwareDetector> _softwareDetectors;
public SoftwareInfoProvider(IEnumerable<ISoftwareDetector> softwareDetectors)
{
_softwareDetectors = softwareDetectors;
}
public async Task<List<SoftwareInfo>> GetSoftwareInfoAsync()
{
var result = new List<SoftwareInfo>();
foreach (var softwareDetector in _softwareDetectors)
{
try
{
var softwareInfo = await softwareDetector.DetectAsync();
if (softwareInfo is not null)
{
result.Add(softwareInfo);
}
}
catch
{
//ignored
}
}
return result;
}
}

135
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/AbpPackageMetadataReader.cs

@ -0,0 +1,135 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.Json;
namespace Volo.Abp.Internal.Telemetry.Helpers;
static internal class AbpProjectMetadataReader
{
private const string AbpPackageSearchPattern = "*.abppkg";
private const string AbpSolutionSearchPattern = "*.abpsln";
private const int MaxDepth = 5;
public static AbpProjectMetaData? ReadProjectMetadata(Assembly assembly)
{
var assemblyPath = assembly.Location;
try
{
var projectDirectory = Path.GetDirectoryName(assemblyPath);
if (projectDirectory == null)
{
return null;
}
var abpPackagePath = FindFileUpwards(projectDirectory, AbpPackageSearchPattern);
if (abpPackagePath.IsNullOrEmpty())
{
return null;
}
var projectMetaData = ReadOrCreateMetadata(abpPackagePath);
var abpSolutionPath = FindFileUpwards(projectDirectory, AbpSolutionSearchPattern);
if (!abpSolutionPath.IsNullOrEmpty())
{
projectMetaData.AbpSlnPath = abpSolutionPath;
}
return projectMetaData;
}
catch
{
return null;
}
}
private static AbpProjectMetaData ReadOrCreateMetadata(string packagePath)
{
var fileContent = File.ReadAllText(packagePath);
var metadata = new AbpProjectMetaData();
using var document = JsonDocument.Parse(fileContent);
var root = document.RootElement;
if (TryGetProjectId(root,out var projectId))
{
metadata.ProjectId = projectId;
}
else
{
metadata.ProjectId = Guid.NewGuid();
WriteProjectIdToPackageFile(root, packagePath, metadata.ProjectId.Value);
}
if (root.TryGetProperty("role", out var roleElement) &&
roleElement.ValueKind == JsonValueKind.String)
{
metadata.Role = roleElement.GetString()!;
}
return metadata;
}
private static void WriteProjectIdToPackageFile(JsonElement root, string packagePath, Guid projectId)
{
using var stream = new MemoryStream();
using (var writer = new Utf8JsonWriter(stream, new JsonWriterOptions { Indented = true }))
{
writer.WriteStartObject();
if (root.ValueKind == JsonValueKind.Object)
{
foreach (var property in root.EnumerateObject())
{
if (property.Name != "projectId")
{
property.WriteTo(writer);
}
}
}
writer.WriteString("projectId", projectId.ToString());
writer.WriteEndObject();
}
var json = Encoding.UTF8.GetString(stream.ToArray());
File.WriteAllText(packagePath, json);
}
private static string? FindFileUpwards(string startingDir, string searchPattern)
{
var currentDir = new DirectoryInfo(startingDir);
var currentDepth = 0;
while (currentDir != null && currentDepth < MaxDepth)
{
var file = currentDir.GetFiles(searchPattern).FirstOrDefault();
if (file != null)
{
return file.FullName;
}
currentDir = currentDir.Parent;
currentDepth++;
}
return null;
}
private static bool TryGetProjectId(JsonElement element, out Guid projectId)
{
if (element.TryGetProperty("projectId", out var projectIdElement) &&
projectIdElement.ValueKind == JsonValueKind.String &&
Guid.TryParse(projectIdElement.GetString(), out projectId))
{
return true;
}
projectId = Guid.Empty;
return false;
}
}

10
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/AbpProjectMetaData.cs

@ -0,0 +1,10 @@
using System;
namespace Volo.Abp.Internal.Telemetry.Helpers;
internal class AbpProjectMetaData
{
public Guid? ProjectId { get; set; }
public string? Role { get; set; }
public string? AbpSlnPath { get; set; }
}

42
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/Cryptography.cs

@ -0,0 +1,42 @@
using System;
using System.Security.Cryptography;
using System.Text;
namespace Volo.Abp.Internal.Telemetry.Helpers;
static internal class Cryptography
{
private const string EncryptionKey = "AbpTelemetryStorageKey";
public static string Encrypt(string plainText)
{
Check.NotNullOrEmpty(plainText, nameof(plainText));
using var aes = Aes.Create();
using var sha256 = SHA256.Create();
aes.Key = sha256.ComputeHash(Encoding.UTF8.GetBytes(EncryptionKey));
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
var encryptor = aes.CreateEncryptor();
var inputBytes = Encoding.UTF8.GetBytes(plainText);
var encryptedBytes = encryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
return Convert.ToBase64String(encryptedBytes);
}
public static string Decrypt(string cipherText)
{
Check.NotNullOrEmpty(cipherText, nameof(cipherText));
using var aes = Aes.Create();
using var sha256 = SHA256.Create();
aes.Key = sha256.ComputeHash(Encoding.UTF8.GetBytes(EncryptionKey));
aes.Mode = CipherMode.ECB;
aes.Padding = PaddingMode.PKCS7;
var decryptor = aes.CreateDecryptor();
var inputBytes = Convert.FromBase64String(cipherText);
var decryptedBytes = decryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
return Encoding.UTF8.GetString(decryptedBytes);
}
}

46
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/Helpers/MutexExecutor.cs

@ -0,0 +1,46 @@
using System;
using System.IO;
using System.Threading;
namespace Volo.Abp.Internal.Telemetry.Helpers;
static internal class MutexExecutor
{
private const string MutexName = "Global\\MyFileReadMutex";
private const int TimeoutMilliseconds = 3000;
public static string? ReadFileSafely(string filePath)
{
using var mutex = new Mutex(false, MutexName);
if (!mutex.WaitOne(TimeoutMilliseconds))
{
return null;
}
try
{
if (!File.Exists(filePath))
{
return null;
}
return File.ReadAllText(filePath);
}
catch (IOException)
{
return null;
}
finally
{
try
{
mutex.ReleaseMutex();
}
catch
{
// Already released or abandoned
}
}
}
}

8
framework/src/Volo.Abp.Core/Volo/Abp/Internal/Telemetry/ITelemetryActivitySender.cs

@ -0,0 +1,8 @@
using System.Threading.Tasks;
namespace Volo.Abp.Internal.Telemetry;
public interface ITelemetryActivitySender
{
Task TrySendQueuedActivitiesAsync();
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save