Create or modify a hand-authored contract (DTO/entity) in a CoreEx domain. USE FOR: new root entity contract, new subordinate/request contract, modifying an existing contract (add property, add interface, wire ref-data), extracting a shared base class. DO NOT USE FOR: reference-data contracts (generated via coreex-refdata / *.CodeGen), Infrastructure persistence models (generated by *.Database CodeGen).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Coreex Contract?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/avanade-coreex-contract)
---
name: coreex-contract
description: "Create or modify a hand-authored contract (DTO/entity) in a CoreEx domain. USE FOR: new root entity contract, new subordinate/request contract, modifying an existing contract (add property, add interface, wire ref-data), extracting a shared base class. DO NOT USE FOR: reference-data contracts (generated via coreex-refdata / *.CodeGen), Infrastructure persistence models (generated by *.Database CodeGen)."
argument-hint: "Optional: contract name, domain, root or subordinate, properties, identifier type"
tags: ["contracts", "dto", "source-generation", "coreex", "partial", "etag", "changelog"]
---
<!--
AI workflow asset — dual-audience notice:
- In the Avanade/CoreEx repository: this file is the authored source. Edit it here.
- In a consumer repository: this file was generated by `dotnet new coreex-ai` (or refreshed via
`dotnet new coreex-ai --force` / the `/coreex-docs-sync` skill). Do not hand-edit it directly —
propose the change upstream in Avanade/CoreEx instead, then refresh once it is released.
-->
# CoreEx: Contract
Guides you through creating or modifying a hand-authored contract (DTO/entity) in `*.Contracts`. Covers root entities, subordinate types, request/response objects, and base class extraction.
## When to Use
- New root entity contract — independently identifiable, persisted, has its own API endpoint
- New subordinate, line-item, or request/response contract (accessed via a parent — may still carry its own identifier)
- Adding or changing properties on an existing contract
- Wiring a ref-data navigation property (`[ReferenceData<T>]`) on an existing contract
- Extracting a shared base class when ≥2 contracts repeat the same fields **and** every shared field is meaningful on each (genuine superset) — not for patch/subset request contracts
## When Not to Use
- Reference data contracts (generated by `*.CodeGen` from `ref-data.yaml`) — use `coreex-refdata`
- Infrastructure persistence models (generated by `*.Database` CodeGen from `dbex.yaml`)
- Domain aggregates, entities, value objects — see `coreex-domain.instructions.md` and the `coreex-aggregate` skill (DDD domains only)
## Quick Reference
**Decisions to resolve from the request and existing code; ask only about unresolved behavior:**
0. **Resolve from state first.** Read the solution-root `AGENTS.md` **Feature Configuration** for `refdata-enabled` (whether `[ReferenceData<T>]` wiring applies) and check whether a `*.Domain` project exists (aggregate-mapping context). Only ask for what is unresolved; include resolved values in the implementation plan.
1. Root or subordinate? (if not explicit)
2. Identifier type? (default `string?` — confirm before using any other type)
3. `IETag` needed? (default yes for root contracts — omit only on explicit request)
4. `IChangeLog` needed? (ask for root contracts — add when created/updated audit trail is required)
5. Sub-folder within `*.Contracts`? (default: flat root — only create one if requested)
6. `[Schema]` override? (only if user explicitly requests a custom event schema name/version)
**Key rules at a glance:**
- `[Contract]` + `partial` on **all** contract classes by default
- Only `[ReferenceData<T>]` properties are `partial` — never make plain properties `partial` (CS9248)
- Map/request-arrange through annotated `XxxCode` properties; use generated typed accessors for reference-data behavior. Pass codes directly to concrete typed destinations via [implicit conversion](/.github/instructions/coreex-contracts.instructions.md#reference-data-code-conversion), not custom conversion helpers; conversion is not validation.
- `[ReadOnly(true)]` on all server-assigned fields (`Id`, `ETag`, `ChangeLog`, computed/derived)
- `[NonNullable]` on any property that is mandatory/required (ultimately not nullable) but declared nullable (`string?`, `int?`) for DTO flexibility — drives `nullable: false` in OpenAPI; not the same as `System.Diagnostics.CodeAnalysis.NotNull`. Never on `Id`/`ETag`/`ChangeLog`; on other `[ReadOnly]` properties only when the type is never a request body
- Do not use `[JsonRequired]` on API request contracts, adapter/HTTP-client wire DTOs, or subscriber payload contracts; use CoreEx validator rules at the relevant boundary, and nullable properties where omission must be distinguished from a supplied default
- Every property needs a `<summary>` XML doc comment
- Same contract type for both API response and event payload — never split them
- Patch/subset contracts (merge-patch, partial-update requests): standalone class with only the needed fields (+ `IETag`) — never inherit a sibling and suppress the rest; inheritance is for genuine supersets only
- For patch fields that distinguish omission from explicit `null` or a supplied default, use `Optional<T>` on the request DTO; do not use it on response/event or persistence contracts
For full workflow, decision trees, and code examples see [`references/workflow.md`](references/workflow.md).
## Key References
- [`/.github/instructions/coreex-contracts.instructions.md`](/.github/instructions/coreex-contracts.instructions.md) — full contract conventions: interfaces, source generation, property rules, localization, inheritance
- [`/.github/instructions/coreex-conventions.instructions.md`](/.github/instructions/coreex-conventions.instructions.md) — XML doc comments, expression bodies, brace style
- Related skills: [`coreex-refdata`](../coreex-refdata/SKILL.md) (generated ref-data contracts), [`coreex-aggregate`](../coreex-aggregate/SKILL.md) (DDD domain object the contract maps to), [`coreex-repository`](../coreex-repository/SKILL.md) (mapping), [`coreex-app-service`](../coreex-app-service/SKILL.md) (consumes contracts)
- Illustrative examples (CoreEx sample — not present in your project):
- [multi-contract examples](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Products.Contracts) — base class, root entity, subordinate, ref-data extension
- [request/response and subordinate contracts](https://github.com/Avanade/CoreEx/tree/main/samples/src/Contoso.Shopping.Contracts)