Automation is necessary for lazy people
Project for dotnet templates
You can build a local prelease version and install this to test it.
On windows run build-and-install-templates.cmd to install all templates.
- Create a personal access token with the right
read:packages - Add the nuget source to the nuget feed.
dotnet nuget add source https://nuget.pkg.github.com/KinNeko-De/index.json --name github --username <MY_USER> --password <MY_PAT>- Install the template
dotnet new install kinneko-de.template.dotnetRead the documentation for more information.
The template must be used to create new projects
To create a new project based on the microservice template use
dotnet new microservice --name-dotnet <MyNameOfDotnetProject> --name-project <MyNameOfProject> --name-domain <MyNameOfDomain>Example
dotnet new microservice --name-dotnet SvcExample --name-project Template --name-domain ExampleThe microservice is created with a database by default.
If the microservice does not need a database, you must remove the database. Use the --database false flag.
dotnet new microservice [..] --database falseThe database port number for local debug is randomly generated to support running multiple services on one localhost.
If you want to use a specific port number us the --database-port flag.
dotnet new microservice [..] --database-port 12345Metrics are created by default using OpenTelemtry
If the microservice does not need metrics, you must remove the metrics. Use the --metric false flag.
dotnet new microservice [..] --metric falseIf you want to create multiple services for the same domain, as example a service and an api gateway, you can also set the the type of the service.
Example
dotnet new microservice --name-dotnet SvcExample --name-project Template --name-domain Example --name-type Api-Gateway --database falseFrom dotnet templating
Choose the right output depending of your context.
| Transform | Input | Output |
|---|---|---|
| Identity | Template.1 | Template.1 |
| Namespace | Template.1 | Template._1 |
| Class Name | Template.1 | Template__1 |
| Lowercase Identity | Template.1 | template.1 |
| Lowercase Namespace | Template.1 | template._1 |
| Lowercase Class Name | Template.1 | template__1 |
Full mapping
| Transform | sourceName | name | generated replacement |
|---|---|---|---|
| Identity | Template.1 | My-App.1 | Template.1 -> My-App.1 |
| Namespace | Template.1 | My-App.1 | Template._1 -> My_App.1 |
| Class Name | Template.1 | My-App.1 | Template__1 -> My_App_1 |
| Lowercase Identity | Template.1 | My-App.1 | template.1 -> my-app.1 |
| Lowercase Namespace | Template.1 | My-App.1 | template._1 -> my_app.1 |
| Lowercase Class Name | Template.1 | My-App.1 | template__1 -> my_app_1 |
Excluding template only config
use the conditional expression templateonly to exlude code that is only there for the template and should never be take to the generated project.
Note Not all replacement are already implemented in the template