-
Notifications
You must be signed in to change notification settings - Fork 14
CLI Tool customization
The Harmony Core CLI tool has a set of customization points to allow you to change how it behaves in your environment. These customization points take the form of .csx (csharp script) files.
During the load process, the cli tool reads the contents of your Harmony.Core.CodeGen.json
file. It de-serializes this file into the Solution
class that we use internally for all operations around configuration and codegen. If you have custom steps that are required before this solution is loaded you can put a script file at Config\LoadSolution.csx
in your solution folder. Below is an example LoadSolution.csx file
class MySolutionLoader
{
public static async Task<Solution> LoadSolution(string targetJsonFile, string solutionDir, Action<string> logger)
{
//var processResult = await Dbl.RunDBR(myWorkingDirectory, cmdline, (logMsg) => {/*log messages are returned here*/});
logger("Hello from a custom solution loader");
var loadedSolution = Solution.LoadSolution(targetJsonFile, solutionDir);
logger("Hello from after the solution was loaded");
return loadedSolution;
}
}
return (Func<string, string, Action<string>, Task<Solution>>)MySolutionLoader.LoadSolution;
During code generation, the Harmony Core CLI tool uses its built in generators to determine what templates are generated and what parameters are passed in during that generation process. You can add new generator types or override existing generator types. The builtin generators are named as follows
- ODataGenerator
- ModelGenerator
- TraditionalBridgeGenerator
- SignalRGenerator
- WebApiGenerator
- EFCoreGenerator
You can find all their definitions here
the folder Generators/Enabled
will be searched and all *.csx files will be compiled/run. The name of the file (without extension) is what determines the generators name. For example in order to override the ODataGenerator
you would create a file called ODataGenerator.csx
in the Generators/Enabled
folder
The following code is an example generator override for OData that adds a new codegen task for all structures marked for odata support.
public class CustomODataGenerator : ODataGenerator
{
public override void ApplyDefaults(Solution solution)
{
}
public override List<string> ValidateSolution(Solution solution)
{
return new List<string>();
}
public override List<CodeGenTask> GenerateTasks(Solution solution)
{
var baseTasks = base.GenerateTasks(solution);
baseTasks.Add(StructureTaskHelper(solution, "Generate controller properties partial classes", solution.ControllersNamespace, solution.ControllersFolder, false, nameof(ODataGenerator), new string[] { "ODataControllerPropertyEndpoints" }, null));
return baseTasks;
}
}
new CustomODataGenerator()
-
Tutorial 2: Building a Service from Scratch
- Creating a Basic Solution
- Enabling OData Support
- Configuring Self Hosting
- Entity Collection Endpoints
- API Documentation
- Single Entity Endpoints
- OData Query Support
- Alternate Key Endpoints
- Expanding Relations
- Postman Tests
- Supporting CRUD Operations
- Adding a Primary Key Factory
- Adding Create Endpoints
- Adding Upsert Endpoints
- Adding Patch Endpoints
- Adding Delete Endpoints
-
Harmony Core Code Generator
-
OData Aware Tools
-
Advanced Topics
- CLI Tool Customization
- Adapters
- API Versioning
- Authentication
- Authorization
- Collection Counts
- Customization File
- Custom Field Types
- Custom File Specs
- Custom Properties
- Customizing Generated Code
- Deploying to Linux
- Dynamic Call Protocol
- Environment Variables
- Field Security
- File I/O
- Improving AppSettings Processing
- Logging
- Optimistic Concurrency
- Multi-Tenancy
- Publishing in IIS
- Repeatable Unit Tests
- Stored Procedure Routing
- Suppressing OData Metadata
- Traditional Bridge
- Unit Testing
- EF Core Optimization
- Updating a Harmony Core Solution
- Updating to 3.1.90
- Creating a new Release
-
Background Information