Skip to content

onelioubov/DotnetTemplateDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DotnetTemplateDemo

This is a demo of how custom .NET templates can be used to quickly create a functioning and deployable API. This includes:

  • The creation of a local and remote Git repository on GitHub during template-invocation.

    • Requires GitHub CLI configured for your GitHub account.
    • Currently only works on Linux and MacOS, but I have plans to make it friendly to Windows as well (unless you have WSL, in which case, you should be good).
  • A Terraform module to create a Resource Group, Web App, and Application Insights resources within Microsoft Azure.

    • Please note that this assumes you have the following cloud resources for this to be deployed:

      • Azure Subscription.
      • Azure Storage Account with a container for the Terraform state files.
      • Azure App Service Plan to deploy the Web App to.

      The reason these resources need to be pre-created is because I'm assuming you would be running multiple web apps out of a single App Service Plan (that is managed outside of the actual repo containing your API code). If that's not the case, an App Service Plan resource can always be added to the provided Terraform template.

    • When you're ready to create your resources, make sure you're logged into your account via the Azure CLI and set the Subscription you want to use; then, just run a terraform init and terraform apply to get the resources created.

  • A build pipeline to compile and test your code (and generate a client when ready) using Nuke.

  • A GitHub Action to build and release your API to the resources created by Terraform. This runs automatically on push to the remote [main] branch.

    • Please note that there is still a manual step to include the publish profile from the newly-created Azure Web App (you should be able to get it as an output when you create the web app via Terraform) as a GitHub repo secret named azureWebAppPublishProfile. This needs to be done before you push to [main].
  • A GitHub Action to package the template itself and push it to a NuGet feed for further distribution.

Some Caveats

  • Ultimately, this template has a few hard-coded values, such as ones for the NuGet feed and the pre-created resources in Azure (the App Service Plan and Storage Account names). This is for the purposes of showing how it can be tailored to your org (including naming conventions and some standard variables used throughout the company), where the "org" in this specific case is my GitHub account, NuGet feed, and Azure Subscription.

  • This is not for general use as it will not work for you out of the box (unless you actually change the aforementioned hard-coded values to your own).

  • This is for the purposes of demonstrating how custom .NET templates can be used and is not a statement on how the code within the template should actually be structured (even though some of my opinions do apply here). There are probably a few things in here that you don't want to do in a live application. However, there are some resources below pertaining to the items I've implemented in this repo; they're still good to have in your toolbox, even if the demo implementation of them does not necessarily show their best usage.

Resources

General .NET Tempate

Microsoft documentation for .NET Tempates
Microsoft custom template tutorial
.NET Template Parameter Generators
Post Action Registry
Testing Your Templates
Useful Microsoft blog post

Miscellaneous Resources

Recommended .NET project structure
Microsoft doc for NSwag Swagger specification
Microsoft doc for healthchecks
Build automation with Nuke
GitVersion configuration
Serilog for logging
Using appsettings.json for Serilog configuration
Deploying Azure App Service with GitHub Actions
Documenting Architecture Decisions
Another ADR Resource
GitHub CLI

If you have any questions about this repo, feel free to reach out!

About

Demo of a custom dotnet template project.

Resources

Stars

Watchers

Forks

Releases

No releases published