.NET Templates for backend applications and open-source components.
This project provides templates that include backed-in patterns and best practices based on experience of implementing many solutions using Microsoft technologies.
Generated projects can:
Install the .NET Core SDK
Install the templates locally
dotnet new -i NV.Templates
Run the template with the relevant options:
dotnet new nv-backend -n <project name> -C <company name> [options]
By default, the project will only generate a Core
library to host the
core business logic of the application.
To generate suitable hosts to run and expose it, use the following options:
Option | Description |
---|---|
--RestApi | Generates an ASP.NET Core MVC project suitable for exposing REST APIs |
--SPA | Generates an ASP.NET Core project suitable for hosting SPAs |
--Functions | Generates an Azure Functions project |
--Console | Generates a Console (command-line) project |
--Auth | Add authentication (JWT-based) support in Web projects |
--Azure | Add Azure ARM Template and DevOps Pipeline |
Options can be combined, e.g.
dotnet new nv-backend -n <project name> -C <company name> --RestApi --SPA --Functions --Console --Auth
For more details on each project type, see the Features / Backend section.
Run the template:
dotnet new nv-netstandard-component -n <component name> -C <company name>
For more details on what's provided, see the Features / Component section.
Regardless of the options provided to the template, there is always 2 projects
that are generated: Core
and Core.Tests
, along with some supporting solution files.
Here is the set of feature provided as part of the Core feature set:
Core
: a netstandard2.0
library where the business logic of the application
is meant to reside. Contains:
IApplicationInfo
/ ApplicationInfo
service that represents the execution
environment of the application itselfIOperationContext
/ OperationContext
service that represents a the execution
environment of a single operation executed by the library; it is meant to be
registered as a Scoped service, and the lifetime of it must be managed by the
Dependency Injection containerFramework
namespace) IdGenerator
utility class to generate unique ids as reasonably readable stringsFramework/Continuation
) as the preferred method to handle pagination
(as opposed to offset pagination)Exception
classes to handle common cases
(ConcurrencyException
, DependencyException
, NotFoundException
)ServiceCollectionExtensions
)OperationContext
class for an example)Refit
: all HttpClient
options are standardized and Polly
parameters are appliedCore.Tests
: a xUnit project for unit-tests. Contains:
OptionsHelper
to help load Options from unit-tests projects configurationEntityFactory
to help implement the Object Mother unit testing patternILogger
to the standard xUnit outputSolution Items files: Various solution files that apply to all projects:
Directory.Build.props
)TemplateVersion
that is set
to the template version used during project generationATTRIBUTIONS.txt
file to collect all
NuGet packages license information to ensure complianceImplementation Get Started
[RegisterXXXService]
attributes to be auto-registered in Dependency InjectionCore.Tests
projectUsing the library
In order to use the library in the context of an application, it needs to be setup in a specific way. While the template options for head projects provide such an environment, if you need to do it yourself here is what's needed:
IServiceCollection.AddCore
extension methodIServiceProvider.CreateScope
)When using the --RestApi
option, 2 projects are added to the solution:
Web
: An ASP.NET Core application setup for exposing the Core library as a Rest API. Contains the following features:
/api/v1/...
)AspNetCoreRequestTracing
componentFramework.Middleware.ExceptionHandler
)
and configured for the exception classes provided in the Core project/attributions.txt
handler configured, to expose the ATTRIBUTIONS.txt
file
the includes 3rd-party NuGet licenses/api/info
endpoint that exposes IApplicationInfo
information/health
endpointCore
X-OperationId
header with the current IOperationContext.Id
valueHelpDeskId
componentWeb.Tests
: a xUnit integration tests project.
Sets up a TestWebApplicationFactory
and a xUnit collection for tests that
automatically starts an in-memory instance of the ASP.NET Core application.
When using the --SPA
option, the Web
project is augmented with the following features:
ClientApp
folder that should host the content of the SPA; it is voluntarily left emptyOnce the solution has been generated, go to the Web\ClientApp
folder and generate the SPA client app here using the SPA tooling of your choice (e.g. Create React App or Angular CLI).
When using the --Auth
option, the Web
project is augmented with the following features:
LocalSettings.Development.json
IOperationContext
Covering the entire scope of authentication and authorization is too large for this documentation. This option is only there to provide a starting point. Please refer to the ASP.NET Core documentation for more info.
When using the --Functions
option, 2 projects are added to the solution:
Functions
: an Azure Functions project
Functions.Tests
: a xUnit project for unit testing the functions
When using the --Console
option, 2 projects are added to the solution:
Console
: a .NET Core console application
CommandLineUtils
Console.Tests
: a xUnit project for unit testing the commands
When using the --Azure
option, an Azure Resource Manager template is added to the solution.
To deploy the infrastructure, please install the Azure CLI and run the following commands:
$ az group create -l <Resource Group Location> -n <Name of the Resource Group>
$ az deployment group create --resource-group <Name of the Resource Group> --template-file azure.azrm.json --parameters projectName=<Project Name> environment=<Environment> billTo=<Dept or Individual> managedBy=<Dept or Individual>
e.g.
$ az group create -l canadacentral -n MyAwesomeApp.QA
$ az deployment group create --resource-group MyAwesomeApp.QA --template-file azure.azrm.json --parameters projectName=aweapp environment=qa billTo=HR managedBy=john.doe@example.org
The template has many parameters documented, but here is a few items included:
Also, an Azure DevOps build pipeline is included to get started faster. This is intended to be a starting point more than a turn key solution though.
Provides a base repository, solution and projects to create an open-source component.
Includes:
netstandard2.0
library for the componentDirectory.Build.props
)TemplateVersion
that is set
to the template version used during project generationazure-pipeline.yml
CI build file, along with an adequate GitVersion configurationREADME.md
fileCHANGELOG.md
fileLICENSE
filePlease consult the CHANGELOG for more information about version history.
This project is licensed under the Apache 2.0 license - see the LICENSE file for details.
Please read CONTRIBUTING.md for details on the process for contributing to this project.
Be mindful of our Code of Conduct.