Application Service Contract Definition
Files referenced in this document
- IMyEntityNameAppService.cs
- MyEntityNameController.cs
- MyEntityNameAppService.cs
- MyEntityNameDto.cs
- GetMyEntityNamesInput.cs
- MyEntityNameCreateDto.cs
- MyEntityNameUpdateDto.cs
- MyEntityNameCreateOrUpdateDtoBase.cs
- MyEntityNamesImportModel.cs
- MyEntityNamesExportModel.cs
- MyEntityName.cs
- IMyEntityNameRepository.cs
Table of Contents
- Introduction
- Interface Inheritance and Extension
- Core Method Details
- Data Transfer Object (DTO) Design
- RESTful API Mapping
- Exception Handling Mechanism
- Import and Export Implementation
- Invocation Examples
- Dependencies and Architecture Diagram
- Conclusion
Introduction
IMyEntityNameAppService is the core application service contract interface for managing MyEntityName entities in the CMS plugin system. This interface extends the ICrudAppService from the ABP framework, providing complete CRUD (Create, Read, Update, Delete) operations, and additionally supports business functions such as batch cloning, sorting adjustment, and data import/export.
Through this interface, front-end or other clients can interact with backend services in a standardized way. All operations are encapsulated through DTOs (Data Transfer Objects), ensuring type safety and data consistency. The interface is exposed as RESTful API endpoints via controllers, supporting advanced query functions like pagination, sorting, and filtering.
Section sources
Interface Inheritance and Extension
The IMyEntityNameAppService interface inherits from the ICrudAppService<TDto, TKey, TGetListInput, TCreateInput, TUpdateInput> generic interface provided by the ABP framework. The specific implementation is as follows:
public interface IMyEntityNameAppService : ICrudAppService<
MyEntityNameDto, // Data Transfer Object
Guid, // Entity Primary Key Type
GetMyEntityNamesInput, // Query Input Parameters
MyEntityNameCreateDto, // Create Input Parameters
MyEntityNameUpdateDto // Update Input Parameters
>
This design naturally equips the service with the following standard operations:
GetAsync(id): Get a single entity by IDGetListAsync(input): Get a list of entities with paginationCreateAsync(input): Create a new entityUpdateAsync(id, input): Update an existing entityDeleteAsync(id): Delete an entity
Based on this, the interface further extends plugin-specific business methods, such as batch deletion, cloning, sort adjustment, import, and export.
Section sources
Core Method Details
Standard CRUD Methods
| Method | Input Parameters | Return Type | Description |
|---|---|---|---|
GetAsync | Guid id | Task<MyEntityNameDto> | Get a single MyEntityName entity by unique identifier |
GetListAsync | GetMyEntityNamesInput input | Task<PagedResultDto<MyEntityNameDto>> | Paged query of MyEntityName list, supporting filtering and sorting |
CreateAsync | MyEntityNameCreateDto input | Task<MyEntityNameDto> | Create a new MyEntityName entity |
UpdateAsync | Guid id, MyEntityNameUpdateDto input | Task<MyEntityNameDto> | Update the MyEntityName entity with the specified ID |
DeleteAsync | Guid id | Task | Delete the MyEntityName entity with the specified ID |
Extended Business Methods
| Method | Input Parameters | Return Type | Description |
|---|---|---|---|
CloneAsync | IEnumerable<Guid> ids | Task<List<MyEntityNameDto>> | Batch clone entities with specified IDs, appending "Copy" tag to names automatically |
DeleteManyAsync | IEnumerable<Guid> ids | Task | Batch delete multiple entities |
AdjustSortAsync | Guid id, int sort | Task | Adjust the sort value of a specified entity and automatically reorder others |
ImportAsync | MyEntityNamesImportModel input | Task | Import MyEntityName data from Excel, supporting incremental updates |
ExportAsync | GetMyEntityNamesInput input | Task<(Dictionary<string, object>, string)> | Export data to Excel format, returning worksheet data and filename |
Section sources
Data Transfer Object (DTO) Design
MyEntityNameDto
Represents the data transfer object for the MyEntityName entity, inheriting from ExtensibleEntityDto<Guid> and implementing IHasConcurrencyStamp for concurrency control.
Property Description:
Code: Code (String)Name: Name (String)Sort: Sort (Integer)Remark: Remark (String)IsDisabled: Is Disabled (Boolean)ConcurrencyStamp: Concurrency Stamp (Used for Optimistic Locking)
Section sources
GetMyEntityNamesInput
Query input parameters, inheriting from ExtensiblePagedAndSortedResultRequestDto, supporting pagination, sorting, and filtering.
Property Description:
Filter: General filter conditionName: Exact query by name
Section sources
MyEntityNameCreateDto and MyEntityNameUpdateDto
Used for create and update operations respectively, both inheriting from MyEntityNameCreateOrUpdateDtoBase.
Common Properties:
Code: CodeName: NameRemark: Remark
Specific Properties:
MyEntityNameCreateDto:Sort(Optional sort value),IsDisabled(Default false)MyEntityNameUpdateDto:ConcurrencyStamp(Concurrency control stamp)
Section sources
Import and Export Models
MyEntityNamesImportModel
Used for Excel import, containing a list of MyEntityNameImportModel, where each model corresponds to a row of data.
MyEntityNamesExportModel
Used for Excel export, defining export column names and widths, annotated via ExcelColumn attribute.
Section sources
RESTful API Mapping
MyEntityNameController maps the IMyEntityNameAppService interface to standard RESTful API endpoints:
Diagram sources
Section sources
Exception Handling Mechanism
The service may throw the following types of exceptions during execution:
-
UserFriendlyException: User-friendly exception, used to prompt specific error information to front-end users, such as:- Name already exists
- Import data format error
- Required field is empty
-
AbpValidationException: Parameter validation exception, automatically triggered by the ABP framework when input DTO does not conform to validation rules. -
ConcurrencyException: Concurrency conflict exception, triggered when multiple users modify the same entity simultaneously (controlled viaConcurrencyStamp).
All exceptions are uniformly handled by the global exception filter (CMSExceptionFilter) and return standardized error responses.
Section sources
Import and Export Implementation
Import Flow
- Frontend uploads Excel file
- Backend reads data from "Configuration" worksheet
- Validate data integrity (duplicate names, required fields, etc.)
- Distinguish between insert and update operations
- Call
CreateAsyncorUpdateAsyncfor batch processing - Transactional commit, rolling back entirely on any failure
Export Flow
- Receive query parameters
GetMyEntityNamesInput - Call
ExportAsyncto get data - Use
MiniExcellibrary to fill template file - Return
FileStreamResultto download file
Diagram sources
Invocation Examples
Get Entity List (GET)
GET /api/v1/MyPluginName/MyEntityName?Filter=test&Sorting=Name&MaxResultCount=10&SkipCount=0
Authorization: Bearer <token>
Create Entity (POST)
POST /api/v1/MyPluginName/MyEntityName
Content-Type: application/json
Authorization: Bearer <token>
{
"code": "TEST001",
"name": "Test Entity",
"remark": "This is a test",
"sort": 1
}
Batch Delete (DELETE)
DELETE /api/v1/MyPluginName/MyEntityName
Content-Type: application/json
Authorization: Bearer <token>
["a1b2c3d4-e5f6-7890-1234-567890abcdef"]
Import Data (POST)
POST /api/v1/MyPluginName/MyEntityName/Import
Content-Type: multipart/form-data
Authorization: Bearer <token>
File: data.xlsx
Export Data (GET)
GET /api/v1/MyPluginName/MyEntityName/Export?Filter=ProductionEnv
Authorization: Bearer <token>
Section sources
Dependencies and Architecture Diagram
Diagram sources
- IMyEntityNameAppService.cs
- MyEntityNameController.cs
- MyEntityNameAppService.cs
- IMyEntityNameRepository.cs
- MyEntityName.cs
Conclusion
The IMyEntityNameAppService interface implements standardized CRUD operations by inheriting from the ABP framework's ICrudAppService and extends practical functions such as cloning, sorting, and import/export on this basis. The interface design follows RESTful principles and encapsulates data through DTOs, ensuring type safety and maintainability.
The controller layer maps interface methods to HTTP endpoints, supporting multiple interaction methods such as JSON and file upload. The entire service adopts dependency injection and repository patterns, achieving decoupling of business logic and data access, facilitating testing and extension.
This interface provides a stable and predictable API contract for the frontend and is the core service contract for entity management in the plugin system.
Section sources