Skip to the content.

Dot Net Api Rest Basic Template

Is a AspNet Core (API Rest) template to provide Best Practices and use several professional componentes and much more. Also everything you have to know how about it and how DotNet Templates work.

Dot Net Api Rest Basic Template

Code Quaity Buid & deploy status for develop Buid & deploy status for master
Quality Gate Status Build Status Build Status
     

API project structure:

k8s folder Kubernetes and helm “.YAML” configuration to publish API to Kubernetes.

azure folder Azure resources scripts to register App in Azure Active Directory (AAD). other scripts, like ARM (Azure Resource Manager), could be added here.

What is going to Learn?

  1. DotNet Templates
  2. API REST using NetCore and best practices:
    • Swagger
    • Serilog and also ‘ApplicationInsight’ + Serilog Extensions.
    • Entity Framework Core for Commands.
    • Automapper. Optional to map Model/entities.
    • Entity Framework.
    • Health Checks.
    • Authentication using Azure Active Directory(AAD App Registration).
  3. Docker
  4. Kubernetes and Helm
  5. Azure Pipelines
  6. SonarQube / Sonar Cloud.io
  7. Api Management & Authenticacion AAD [Future Version]
  8. Azure DevSpaces [Future Version]
  9. And much more.

Blog

All those new Patterns, Tools and Platforms, will be Blog Post entries in elGuerre.com

Runnng the App

  1. Using Kestrel from Visual Studio:
    cd ./content/src/ElGuerre.Items.Api
    dotnet run ...
    
  2. Using Docker from Visual Studio or Docker Command Line:
    cd ./content
    docker build -t items-api .
    docker run items-api
    
  3. Run Entity Framework Migration:
    cd ./content/src/ElGuerre.Items.Api
    dotnet ef migrations add Init --startup-project ..\src\ElGuerre.Items.Api.csproj
    dotnet ef database update --startup-project ..\src\ElGuerre.Items.Api.csproj
    

Generate and publish Template

Package a new template version

Nuget.org

dotnet nuget push AppLogger.1.0.0.nupkg -k xxx -s https://api.nuget.org/v3/index.json Publishing packages

Github (Packages)

Update Nuget.config

Note TOKEN will be generated as follow. More details here.

How to generate github token

Publish a new template version

dotnet nuget push "ElGuerre.ApiRest.Template.1.0.0.nupkg" --source "github"

Publish a new template version

Azure DevOps (Artifacts)

Generate a new token

Update Nuget.config

Publish a new template version

Install and uninstall templates

Clear cache: dotnet nuget locals http-cache --clear Add new templates dotnet new -i ElGuerre.ApiRest.Template::*

Note: List of templeates cached: dotnet nuget locals all --list Note: Remove cached of templatess Http and Temps: dotnet nuget locals http-cache --clear y dotnet nuget locals temp --clear

Azure DevOps Multi-stages

Attach AKS (Azure Kubernetes Services) to ACR (Azure Container Registry)

To authorize AKS to accesos ACR execute the sentence: az aks update -n elguerreaks -g elguerre --attach-acr elguerreacr.azurecr.io

Deploy using Azure Pipeline Multi-Stage Dedploy to PROD Environments

az aks browse --resource-group elguerre --name elguerreaks

Create AKS namespaces ‘dev’, ‘int’ and ‘pro’ :

kubectl apply -f ./k8s/namespace-dev.json
kubectl apply -f ./k8s/namespace-int.json
kubectl apply -f ./k8s/namespace-pro.json

Note: Review azure-pipelines.yml for more detail.