Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 2.47 KB

File metadata and controls

54 lines (38 loc) · 2.47 KB

CoreEx.CodeGen — AI Usage Guide

CoreEx.CodeGen is a development-time code generation tool — it is never deployed at runtime. It reads a ref-data.yaml file and generates the complete reference-data layer (contract, controller, service, repository, mapper) as .g.cs files.

Setup

Create a console project (e.g. MyApp.CodeGen) and add a Program.cs with one line:

await CoreEx.CodeGen.CodeGenConsole.Create().RunAsync(args);

Place ref-data.yaml alongside Program.cs.

ref-data.yaml Structure

collectionSortOrder: Code     # default sort for all reference data collections

entities:
  - name: Status
    idType: Int32              # Id property type; defaults to String. Must be one of: String, Guid, Int32, Int64.
    properties:
      - name: IsExternal
        type: bool
  - name: Country
  - name: Currency

Run the project (dotnet run) to regenerate all .g.cs files after changing the YAML.

Generated Outputs

Output Layer What changes it
{Name}.g.cs (Contracts project root) Contracts ref-data.yaml entity/property config
Controllers/ReferenceDataController.g.cs Api ref-data.yaml route/entity config
ReferenceDataService.g.cs (Application project root) Application ref-data.yaml entity config
Repositories/IReferenceDataRepository.g.cs Application ref-data.yaml entity/repository config
Repositories/ReferenceDataRepository.g.cs Infrastructure ref-data.yaml repository config
Mapping/{Name}Mapper.g.cs Infrastructure ref-data.yaml property/mapping config

Repositories/Mapping are the default dataRepositoriesPath/dataMappingPath folder names — both configurable in ref-data.yaml.

Do Not

  • Do not edit *.g.cs files — they are overwritten on every generation run. Edit ref-data.yaml or the Handlebars templates in the CoreEx.CodeGen package instead.
  • Do not add CoreEx.CodeGen as a runtime dependency — it is a development tool only.

Further Reading

  • README — full YAML schema, script structure, and template customisation reference.
  • Tooling — how *.CodeGen and *.Database projects are used together in the sample solution, including run order and generated-file ownership.
  • Contracts layer — shows generated reference-data contracts ([ReferenceData]) and how ref-data.yaml drives the controller/service/repository layer.