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.
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.
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: CurrencyRun the project (dotnet run) to regenerate all .g.cs files after changing the YAML.
| 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 edit
*.g.csfiles — they are overwritten on every generation run. Editref-data.yamlor the Handlebars templates in theCoreEx.CodeGenpackage instead. - Do not add
CoreEx.CodeGenas a runtime dependency — it is a development tool only.
- README — full YAML schema, script structure, and template customisation reference.
- Tooling — how
*.CodeGenand*.Databaseprojects are used together in the sample solution, including run order and generated-file ownership. - Contracts layer — shows generated reference-data contracts (
[ReferenceData]) and howref-data.yamldrives the controller/service/repository layer.