|
1 | | -# GitHub Copilot Agent Configuration for DKNet Framework |
2 | | - |
3 | | -## Agent Identity |
4 | | -- **Project**: DKNet Framework |
5 | | -- **Type**: .NET 9 Library Collection |
6 | | -- **Focus**: EF Core Extensions, Specifications, Dynamic Predicates |
7 | | -- **Standards**: Enterprise-grade, production-ready code |
8 | | - |
9 | | -## Core Instructions for AI Agent |
10 | | - |
11 | | -### 1. ALWAYS Load Context First |
12 | | -Before generating ANY code, you MUST: |
13 | | -``` |
14 | | -1. Read /memory-bank/README.md (navigation) |
15 | | -2. Read /memory-bank/activeContext.md (current focus) |
16 | | -3. Read /memory-bank/copilot-quick-reference.md (patterns) |
17 | | -4. Read /memory-bank/systemPatterns.md (detailed patterns) |
18 | | -5. Read /memory-bank/copilot-rules.md (complete standards) |
19 | | -``` |
20 | | - |
21 | | -**Priority**: README → activeContext → quick-reference → systemPatterns → copilot-rules |
22 | | - |
23 | | -### 2. Project-Specific Knowledge |
24 | | - |
25 | | -#### Current Development Focus |
26 | | -- **Active Area**: EfCore.Specifications - Dynamic Predicate System |
27 | | -- **Key Features**: |
28 | | - - Dynamic predicate building with `DynamicPredicateBuilder<T>` |
29 | | - - Specification Pattern implementation |
30 | | - - LinqKit integration for expression composition |
31 | | - - TestContainers for integration testing |
32 | | - - Enum validation and type safety |
33 | | - |
34 | | -#### Technology Stack |
35 | | -- **.NET**: 9.0 with C# 13 |
36 | | -- **EF Core**: 9.0 |
37 | | -- **Testing**: xUnit, Shouldly, TestContainers.MsSql, Bogus |
38 | | -- **Dynamic LINQ**: System.Linq.Dynamic.Core, LinqKit |
39 | | - |
40 | | -#### Code Quality Requirements |
41 | | -- `TreatWarningsAsErrors=true` - ZERO warnings allowed |
42 | | -- `<Nullable>enable</Nullable>` - Nullable reference types mandatory |
43 | | -- XML documentation required for all public APIs |
44 | | -- Test coverage: 85%+ target |
45 | | - |
46 | | -### 3. Pattern Recognition Rules |
47 | | - |
48 | | -When you see code involving: |
49 | | - |
50 | | -#### Dynamic Predicates |
51 | | -→ Use: `PredicateBuilder.New<T>()`, `.DynamicAnd()`, `.DynamicOr()` |
52 | | -→ Always: Include `.AsExpandable()` before `.Where()` |
53 | | -→ Pattern: Null-safe dynamic expression building |
54 | | -```csharp |
55 | | -var predicate = PredicateBuilder.New<Product>() |
56 | | - .And(p => p.IsActive) |
57 | | - .DynamicAnd(builder => builder |
58 | | - .With("PropertyName", FilterOperations.Operator, value)); |
59 | | -``` |
60 | | - |
61 | | -#### EF Core Queries |
62 | | -→ Use: `.AsNoTracking()` for read-only |
63 | | -→ Use: `async`/`await` for all database operations |
64 | | -→ Filter: Push to database with `.Where()` before `.ToListAsync()` |
65 | | -→ Avoid: N+1 queries (use `.Include()` or projections) |
66 | | - |
67 | | -#### Tests |
68 | | -→ Framework: xUnit with Shouldly assertions |
69 | | -→ Integration: TestContainers.MsSql (real SQL Server) |
70 | | -→ Naming: `MethodName_Scenario_ExpectedBehavior` |
71 | | -→ Structure: Arrange-Act-Assert |
72 | | - |
73 | | -#### Extension Methods |
74 | | -→ Location: Static classes in `/Extensions` folder |
75 | | -→ Documentation: XML docs with `<summary>`, `<param>`, `<returns>` |
76 | | -→ Naming: Verb-based (e.g., `TryConvertToEnum`, `DynamicAnd`) |
77 | | - |
78 | | -### 4. Code Generation Rules |
79 | | - |
80 | | -#### When Generating Classes |
81 | | -```csharp |
82 | | -// <copyright file="ClassName.cs" company="https://drunkcoding.net"> |
83 | | -// Copyright (c) 2025 Steven Hoang. All rights reserved. |
84 | | -// Licensed under the MIT License. See LICENSE in the project root for license information. |
85 | | -// </copyright> |
86 | | -
|
87 | | -/// <summary> |
88 | | -/// Brief description of the class purpose. |
89 | | -/// </summary> |
90 | | -public class ClassName |
91 | | -{ |
92 | | - private readonly IService _service; |
93 | | - |
94 | | - /// <summary> |
95 | | - /// Description of what this constructor does. |
96 | | - /// </summary> |
97 | | - public ClassName(IService service) |
98 | | - { |
99 | | - _service = service; |
100 | | - } |
101 | | -} |
102 | | -``` |
103 | | - |
104 | | -#### When Generating Methods |
105 | | -```csharp |
106 | | -/// <summary> |
107 | | -/// Description of what the method does. |
108 | | -/// </summary> |
109 | | -/// <typeparam name="T">Description of generic parameter</typeparam> |
110 | | -/// <param name="paramName">Description of parameter</param> |
111 | | -/// <returns>Description of return value</returns> |
112 | | -/// <exception cref="ArgumentNullException">When paramName is null</exception> |
113 | | -public async Task<Result<T>> MethodNameAsync<T>(string paramName) |
114 | | -{ |
115 | | - // Implementation with proper error handling |
116 | | -} |
117 | | -``` |
118 | | - |
119 | | -#### When Generating Tests |
120 | | -```csharp |
121 | | -[Fact] |
122 | | -public void MethodName_WhenScenarioOccurs_ThenExpectedOutcome() |
123 | | -{ |
124 | | - // Arrange: Setup test data and dependencies |
125 | | - var testData = CreateTestData(); |
126 | | - |
127 | | - // Act: Execute the operation under test |
128 | | - var result = _sut.MethodUnderTest(testData); |
129 | | - |
130 | | - // Assert: Verify expected outcomes |
131 | | - result.ShouldNotBeNull(); |
132 | | - result.ShouldBe(expectedValue); |
133 | | -} |
| 1 | +# Project Guidelines |
| 2 | + |
| 3 | +## Context First |
| 4 | +Before making code changes, load project context in this order: |
| 5 | +1. `src/memory-bank/README.md` |
| 6 | +2. `src/memory-bank/activeContext.md` |
| 7 | +3. `src/memory-bank/copilot-quick-reference.md` |
| 8 | +4. `src/memory-bank/systemPatterns.md` |
| 9 | +5. `src/memory-bank/copilot-rules.md` |
| 10 | + |
| 11 | +## Architecture |
| 12 | +- DKNet is a `.NET 10` library suite for enterprise API development using **DDD** and **Onion Architecture**. |
| 13 | +- Keep domain behavior in domain types (aggregate roots, entities, value objects); keep infrastructure concerns in EF Core, messaging, and service packages. |
| 14 | +- Prefer Specification + Repository patterns for query composition and reuse. |
| 15 | +- For dynamic predicates, compose with LinqKit and use `.AsExpandable()` before `.Where()`. |
| 16 | +- Keep boundaries clear across `Core`, `EfCore`, `Services`, `SlimBus`, and `AspNet` modules. |
| 17 | + |
| 18 | +## Build and Test |
| 19 | +Run commands from `src/` unless noted. |
| 20 | + |
| 21 | +```bash |
| 22 | +dotnet restore DKNet.FW.sln |
| 23 | +dotnet build DKNet.FW.sln --configuration Release |
| 24 | +dotnet test DKNet.FW.sln --configuration Release --settings coverage.runsettings --collect "XPlat Code Coverage" |
| 25 | +dotnet pack DKNet.FW.sln --configuration Release |
134 | 26 | ``` |
135 | 27 |
|
136 | | -### 5. Anti-Patterns to NEVER Generate |
137 | | - |
138 | | -❌ **NEVER** use InMemory database for EF Core tests (use TestContainers) |
139 | | -❌ **NEVER** mix sync and async code (`result = asyncMethod().Result`) |
140 | | -❌ **NEVER** materialize queries early (`.ToList()` then `.Where()`) |
141 | | -❌ **NEVER** forget `.AsExpandable()` with LinqKit predicates |
142 | | -❌ **NEVER** omit XML documentation on public APIs |
143 | | -❌ **NEVER** include secrets or credentials in code |
144 | | -❌ **NEVER** use `async void` (except event handlers) |
145 | | -❌ **NEVER** catch exceptions without logging |
146 | | -❌ **NEVER** ignore nullable warnings |
147 | | -❌ **NEVER** violate the Single Responsibility Principle |
148 | | - |
149 | | -### 6. Decision Making Guidelines |
150 | | - |
151 | | -#### When Asked to Implement a Feature |
152 | | -1. **Check** `activeContext.md` - Is this aligned with current focus? |
153 | | -2. **Review** `systemPatterns.md` - What pattern should be used? |
154 | | -3. **Reference** `copilot-quick-reference.md` - Are there templates? |
155 | | -4. **Generate** code following established patterns |
156 | | -5. **Include** comprehensive tests (arrange-act-assert) |
157 | | -6. **Document** with XML comments |
158 | | -7. **Verify** zero warnings after build |
159 | | - |
160 | | -#### When Asked to Fix a Bug |
161 | | -1. **Understand** the issue (read error messages, stack traces) |
162 | | -2. **Check** existing tests - Do they cover this scenario? |
163 | | -3. **Add** test that reproduces the bug (TDD approach) |
164 | | -4. **Fix** the code to make test pass |
165 | | -5. **Verify** all tests still pass |
166 | | -6. **Document** the fix in comments if non-obvious |
167 | | - |
168 | | -#### When Asked to Refactor |
169 | | -1. **Ensure** tests exist and pass before refactoring |
170 | | -2. **Make** small, incremental changes |
171 | | -3. **Run** tests after each change |
172 | | -4. **Keep** functionality identical (tests prove this) |
173 | | -5. **Improve** code quality, readability, performance |
174 | | -6. **Update** documentation if patterns change |
175 | | - |
176 | | -### 7. Quality Checklist |
177 | | - |
178 | | -Before considering code complete, verify: |
179 | | -- [ ] Compiles without warnings |
180 | | -- [ ] All tests pass |
181 | | -- [ ] XML documentation on public APIs |
182 | | -- [ ] File header present |
183 | | -- [ ] Follows naming conventions |
184 | | -- [ ] Null safety considered |
185 | | -- [ ] Error handling implemented |
186 | | -- [ ] Performance considered (async, filtering) |
187 | | -- [ ] Security considered (no secrets, validation) |
188 | | -- [ ] Patterns followed (Specification, Repository, etc.) |
189 | | - |
190 | | -### 8. Communication Guidelines |
191 | | - |
192 | | -#### When Explaining Code |
193 | | -- Reference the specific pattern from `systemPatterns.md` |
194 | | -- Include code examples from actual codebase |
195 | | -- Explain WHY, not just WHAT |
196 | | -- Link to relevant documentation |
197 | | - |
198 | | -#### When Suggesting Improvements |
199 | | -- Reference quality standards from `copilot-rules.md` |
200 | | -- Show before/after comparisons |
201 | | -- Explain benefits (performance, maintainability, etc.) |
202 | | -- Consider impact on existing code |
203 | | - |
204 | | -#### When Reporting Issues |
205 | | -- Provide error messages and stack traces |
206 | | -- Show relevant code context |
207 | | -- Suggest potential solutions |
208 | | -- Reference similar solved issues if available |
209 | | - |
210 | | -### 9. Special DKNet Framework Features |
211 | | - |
212 | | -#### Dynamic Predicate Builder |
213 | | -- **Purpose**: Build EF Core queries from runtime conditions |
214 | | -- **Usage**: `.DynamicAnd(builder => builder.With(...))` |
215 | | -- **Key**: Type-safe, null-safe, composable |
216 | | -- **Gotcha**: Always use `.AsExpandable()` with LinqKit |
217 | | - |
218 | | -#### Specification Pattern |
219 | | -- **Purpose**: Encapsulate query logic in reusable specifications |
220 | | -- **Base Class**: `Specification<TEntity>` |
221 | | -- **Features**: Criteria, Includes, OrderBy |
222 | | -- **Usage**: Compose with `.And()`, `.Or()` using LinqKit |
223 | | - |
224 | | -#### Type Extensions |
225 | | -- **Purpose**: Type checking and conversion utilities |
226 | | -- **Key Method**: `TryConvertToEnum<TEnum>` with validation |
227 | | -- **Usage**: Safe enum conversion with culture-invariant parsing |
228 | | -- **Pattern**: Return `bool`, `out` parameter for result |
229 | | - |
230 | | -#### TestContainers Integration |
231 | | -- **Purpose**: Real SQL Server for integration tests |
232 | | -- **Setup**: `IAsyncLifetime` fixture pattern |
233 | | -- **Benefits**: Catches SQL-specific issues, accurate testing |
234 | | -- **Usage**: One container per test class, dispose properly |
235 | | - |
236 | | -### 10. Context-Aware Responses |
237 | | - |
238 | | -When the user asks about: |
239 | | - |
240 | | -**"How do I..."** |
241 | | -→ Check `copilot-quick-reference.md` for templates |
242 | | -→ Provide code example following DKNet patterns |
243 | | -→ Include test example |
244 | | -→ Reference full documentation |
245 | | - |
246 | | -**"Why does..."** |
247 | | -→ Explain based on patterns in `systemPatterns.md` |
248 | | -→ Reference technical constraints in `techContext.md` |
249 | | -→ Show alternatives if applicable |
250 | | - |
251 | | -**"Is this correct..."** |
252 | | -→ Compare against `copilot-rules.md` standards |
253 | | -→ Check pattern usage in `systemPatterns.md` |
254 | | -→ Suggest improvements if needed |
255 | | -→ Explain reasoning |
256 | | - |
257 | | -**"What should I do next..."** |
258 | | -→ Check `activeContext.md` for current priorities |
259 | | -→ Reference `progress-detailed.md` for roadmap |
260 | | -→ Suggest aligned with project goals |
261 | | - |
262 | | ---- |
263 | | - |
264 | | -## Quick Reference for Agent |
265 | | - |
266 | | -### File Priority (Load Order) |
267 | | -1. `/memory-bank/README.md` - Navigation |
268 | | -2. `/memory-bank/activeContext.md` - Current work |
269 | | -3. `/memory-bank/copilot-quick-reference.md` - Quick patterns |
270 | | -4. `/memory-bank/systemPatterns.md` - Detailed patterns |
271 | | -5. `/memory-bank/copilot-rules.md` - Complete standards |
272 | | - |
273 | | -### Critical Patterns |
274 | | -- **Specification Pattern**: Reusable query specifications |
275 | | -- **Dynamic Predicates**: Runtime query building |
276 | | -- **Repository Pattern**: Data access abstraction |
277 | | -- **TestContainers**: Real database testing |
278 | | -- **Arrange-Act-Assert**: Test structure |
279 | | - |
280 | | -### Non-Negotiable Standards |
281 | | -- Zero warnings (`TreatWarningsAsErrors=true`) |
282 | | -- Nullable types enabled |
283 | | -- XML docs on public APIs |
284 | | -- Async/await for I/O |
285 | | -- TestContainers for integration tests |
286 | | - |
287 | | -### Common Tasks |
288 | | -- Adding filter operation → Update `DynamicPredicateBuilder`, add tests |
289 | | -- Creating specification → Inherit from `Specification<T>`, implement `Criteria` |
290 | | -- Writing test → xUnit, Shouldly, `MethodName_Scenario_Outcome` naming |
291 | | -- Adding extension → Static class, XML docs, comprehensive tests |
292 | | - |
293 | | ---- |
294 | | - |
295 | | -**Agent Version**: 1.0 |
296 | | -**Last Updated**: November 5, 2025 |
297 | | -**Status**: Production Ready |
298 | | - |
299 | | -**Remember**: This configuration ensures consistent, high-quality code generation aligned with DKNet Framework standards and patterns. |
300 | | - |
| 28 | +## Code Style |
| 29 | +- Treat warnings as errors (`TreatWarningsAsErrors=true`) and keep nullable annotations correct (`Nullable=enable`). |
| 30 | +- Add XML documentation for all public APIs. |
| 31 | +- Use async I/O end-to-end; avoid sync-over-async (`.Result`, `.Wait()`). |
| 32 | +- Follow existing naming conventions and static extension class placement. |
| 33 | +- Keep changes minimal and scoped; do not refactor unrelated areas. |
| 34 | + |
| 35 | +## Conventions |
| 36 | +- Test stack: xUnit + Shouldly. |
| 37 | +- Integration tests should use Testcontainers/real provider behavior (avoid EF Core InMemory for integration scenarios). |
| 38 | +- Test naming: `MethodName_Scenario_ExpectedBehavior`. |
| 39 | +- For read-only EF queries, prefer `.AsNoTracking()`. |
| 40 | +- Filter in database (compose `IQueryable`) before materialization. |
| 41 | + |
| 42 | +## Pitfalls |
| 43 | +- Forgetting `.AsExpandable()` with LinqKit dynamic predicates breaks expression expansion. |
| 44 | +- Early materialization (`ToList()` before filtering) causes performance and correctness issues. |
| 45 | +- Missing XML docs or nullable fixes will fail CI due to strict build settings. |
| 46 | + |
| 47 | +## Key References |
| 48 | +- Architecture and DDD: `docs/Architecture.md` |
| 49 | +- Contribution workflow and commands: `docs/Contributing.md` |
| 50 | +- Testing strategy: `TESTING_STRATEGY.md`, `src/coverage.runsettings` |
| 51 | +- Build/analyzer settings: `src/Directory.Build.props`, `src/Directory.Packages.props`, `src/global.json` |
| 52 | +- Detailed project guidance: `src/memory-bank/` |
0 commit comments