scaffold-read
Guide for adding a new read operation (query) to the Backend. Focuses on Marten queries, Projections, Caching, and Pagination.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Follow this guide to implement a read-only endpoint in the Backend (ApiService) using strict project standards.
-
Define the DTO
- Create a
recordinsrc/Shared/BookStore.Shared/Models/. -
Properties:
Guid Id,string Name, etc. -
Localization (Text): Map localized text to a single
string(e.g.,string Description), NOT a Dictionary. -
Data Maps: Use
IReadOnlyDictionary<string, T>for non-text maps (e.g.,Prices).
- Create a
-
Define the Projection
- Open/Create
src/BookStore.ApiService/Projections/{Resource}Projection.cs. -
Template:
templates/Projection.cs -
Localization Storage: Use
Dictionary<string, string>for storing all translations (e.g.,Descriptions,Biographies). - Reference: See marten-guide for projection patterns.
- Open/Create
-
Expose the Endpoint
- Open
src/BookStore.ApiService/Endpoints/{Resource}Endpoints.cs. -
Template:
templates/Endpoint.cs
- Open
-
Implement Caching (HybridCache)
- Wrap logic in
cache.GetOrCreateLocalizedAsync(auto-appends culture to cache key). - Key: Include page, size, sort, order (culture added automatically).
-
Tags: Use
CacheTags.{Resource}Listor$\"{Resource.ToLower()}:{id}\". -
Options: Set
Expiration(L2/Redis) andLocalCacheExpiration(L1/memory). - Reference: See caching-guide for HybridCache patterns.
- Wrap logic in
-
Implement Query (Marten)
- Use
await using var session = store.QuerySession();. -
Query:
session.Query<Projection>() -
Filter:
.Where(x => !x.Deleted) -
Paginate:
.ToPagedListAsync(page, pageSize, token)
- Use
-
Apply Localization
- Map from Projection to DTO.
-
Text: Use
LocalizationHelper.GetLocalizedValue(proj.Descriptions, culture, defaultCulture, ""). -
Maps: Copy directly (e.g.,
Prices = proj.Prices).
-
Client Integration
-
Interface: Create
src/Client/BookStore.Client/IGet{Resource}Endpoint.csmanually. -
Registration: Add to
BookStoreClientExtensions.cs.
-
Interface: Create
// turbo 8. Verify
- Run
/verify-featureto ensure build and tests pass.
Related Skills
Prerequisites:
-
/scaffold-write- Ensure write operations exist before adding reads -
/scaffold-projection- For detailed projection patterns and localization
Next Steps:
-
/scaffold-frontend-feature- Create UI to consume the query -
/scaffold-test- Create integration tests for the endpoint -
/verify-feature- Complete verification
Debugging:
-
/debug-cache- If caching issues occur
See Also:
- scaffold-projection - Advanced projection patterns
- scaffold-write - Related write operations
- caching-guide - HybridCache patterns
- localization-guide - Localization patterns
- ApiService AGENTS.md - Caching and localization patterns
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!