Skip to content

Add conventions: local functions, tests vs production code, EF navigations#4

Merged
KaliCZ merged 4 commits into
mainfrom
conventions/no-local-functions
Jul 16, 2026
Merged

Add conventions: local functions, tests vs production code, EF navigations#4
KaliCZ merged 4 commits into
mainfrom
conventions/no-local-functions

Conversation

@KaliCZ

@KaliCZ KaliCZ commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Three written conventions (wording taken from the global rules), all docs-only — the codebase already complies with each. Each lives in CLAUDE.md and docs/technical-requirements.md.

No nested local functions — write a normal method

Don''t reach for local functions; extract a private method instead. A one-liner local function can occasionally be acceptable, but that''s an edge case, not something to aim for. No Roslyn analyzer covers this, so it lives as a written convention.

Verified: swept all C# for local-function declaration shapes (modifier-prefixed, built-in/custom/tuple return types, expression-bodied, top-level-statement files) — zero hits.

Tests never reshape production code

We use DDD: the domain model is designed for the domain, not for testability. If a test needs some capability, the test figures out how to achieve it — never add methods, parameters, setters, or hooks to production code just so a test can reach something. Dependency injection should be enough; otherwise the test manipulates state itself (seeding through EF, reflection as a last resort).

Verified: all entity properties are private set, no InternalsVisibleTo anywhere, tests seed exclusively through domain entities + EF. (public partial class Program; stays — the standard WebApplicationFactory host idiom, not a domain signature.)

Entity Framework: set the navigation property together with the FK

When assigning a relationship by ID (e.g. ProductId), also assign the navigation property (Product) — in constructors, factory methods, and setters alike — so that right after the call, something.Product is usable and non-null. The exception is performance-sensitive work like inserting thousands of rows in a batch: there it''s fine to set only the ID rather than load entities into memory that nothing will read.

Verified: the current model has no reference navigations at all (Product.Reviews and Review.Votes are collection navigations on the principal side; dependents carry only FKs), so no call site can violate the rule today — it binds the moment a reference navigation is introduced.

🤖 Generated with Claude Code

KaliCZ and others added 2 commits July 16, 2026 00:16
Extract a normal method instead; a trivial helper of up to ~3 lines is the
only exception.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@KaliCZ KaliCZ changed the title Add convention: no local functions inside methods Add conventions: no local functions; tests never reshape production code Jul 16, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@KaliCZ KaliCZ changed the title Add conventions: no local functions; tests never reshape production code Add conventions: local functions, tests vs production code, EF navigations Jul 16, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@KaliCZ
KaliCZ merged commit bb87b59 into main Jul 16, 2026
3 checks passed
@KaliCZ
KaliCZ deleted the conventions/no-local-functions branch July 17, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant