Skip to content

Create Contracts template #66

@gpreviatti

Description

@gpreviatti

Plan: New standalone Contracts template

Create a new standalone template at templates/Contracts that mirrors the existing BFF src/Contracts project exactly, and add a basic xUnit unit-test project to verify each contract type can be instantiated correctly. The safest approach is to reuse existing repo patterns from templates/Bff and templates/Full (template metadata, central package management, and test naming conventions) while keeping scope focused on contracts + instantiation tests.

Steps

  1. Phase 1 — Scaffold standalone template shell
    1.1 Create templates/Contracts folder structure with .template.config, src, and tests.
    1.2 Add templates/Contracts/.template.config/template.json using a new identity/shortName/sourceName for this template.
    1.3 Add template-level Directory.Build.props and Directory.Packages.props so Contracts.csproj and test project resolve framework/package versions correctly. (blocks 2 and 3)
  2. Phase 2 — Clone Contracts project content (exact clone)
    2.1 Copy templates/Bff/src/Contracts/Contracts.csproj to templates/Contracts/src/Contracts/Contracts.csproj preserving GenerateDocumentationFile and protobuf inclusion.
    2.2 Copy all source files exactly from BFF Contracts: Common/BaseRequest.cs, Common/BaseResponse.cs, Orders/CreateOrderRequest.cs, Orders/OrderDto.cs, Protos/payment.proto.
    2.3 Preserve namespaces and XML docs as-is to keep behavior and generated artifacts aligned with the original. (depends on 1)
  3. Phase 3 — Add basic unit tests for contract instantiation
    3.1 Create templates/Contracts/tests/UnitTests/UnitTests.csproj with xUnit + test SDK packages and ProjectReference to src/Contracts/Contracts.csproj.
    3.2 Add one or more test files verifying object creation for all public contract types:
    • BaseRequest, BasePaginatedRequest
    • BaseResponse, BaseResponse<TData>, BasePaginatedResponse<TData>
    • CreateOrderRequest, CreateOrderItemRequest
    • OrderDto, ItemDto
      3.3 Use repo test naming style (GivenA...When...Then...) with [Fact(DisplayName = nameof(...))], and assert key properties to confirm constructor/property initialization works. (depends on 2)
  4. Phase 4 — Solution and discoverability wiring
    4.1 Add templates/Contracts/Hexagonal.Solution.Template.Contracts.slnx including src/Contracts and tests/UnitTests projects.
    4.2 Update top-level Readme.md with install/use command for new short name.
    4.3 Decide whether CI should validate this new template now or in a follow-up (recommended now if pipeline cost is acceptable). (4.3 can run in parallel with 4.2)
  5. Phase 5 — Verification
    5.1 Restore/build the new template projects.
    5.2 Run unit tests for templates/Contracts/tests/UnitTests.
    5.3 Optional smoke test: install template locally and instantiate a sample solution using its short name, then build/test generated output.

Relevant files

  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Bff/src/Contracts/Contracts.csproj — source clone baseline for project config.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Bff/src/Contracts/Common/BaseRequest.cs — base request records to mirror.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Bff/src/Contracts/Common/BaseResponse.cs — response records and generic base types to mirror/test.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Bff/src/Contracts/Orders/CreateOrderRequest.cs — order request records to mirror/test.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Bff/src/Contracts/Orders/OrderDto.cs — DTO records to mirror/test.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Bff/.template.config/template.json — template metadata reference pattern.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Full/tests/UnitTests/UnitTests.csproj — unit-test csproj dependency pattern.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/templates/Full/tests/UnitTests/Domain/NotificationTests.cs — test naming/assertion style reference.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/Readme.md — add usage docs for new template short name.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/.github/workflows/validate.yml — optional CI inclusion for new template validation.
  • c:/Users/gpreviatti/Projects/Others/hexagonal-solution-template/.github/workflows/publish.yml — optional publish prerequisite update if CI job is added.

Verification

  1. Confirm new template metadata is discoverable and unique (identity + shortName).
  2. Build templates/Contracts/src/Contracts/Contracts.csproj successfully.
  3. Run tests in templates/Contracts/tests/UnitTests and confirm all pass.
  4. Verify protobuf generation still works (generated C# appears under obj/.../Protos).
  5. Smoke-create a project from the new template short name and verify generated project builds and unit tests run.

Decisions

  • Included scope:
    • New standalone folder: templates/Contracts.
    • Exact clone behavior/content of current BFF src/Contracts project.
    • Basic unit-test coverage focused on contract instantiation correctness.
  • Excluded scope:
    • No refactor/renaming of contract models.
    • No advanced behavioral validation beyond instantiation/property checks.
  • Architectural fit:
    • A contracts-only template impacts contract boundary artifacts (DTOs/requests/responses) and test layer only; no domain aggregate changes, no infra adapters, no security-sensitive runtime logic.

Further Considerations

  1. CI inclusion choice: add validation jobs for templates/Contracts now (recommended) vs. defer to keep this PR smaller.
  2. Package versioning strategy: copy full Directory.Packages.props from BFF for consistency vs. trim to minimal package set for contracts-only template.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions