{"id":21730077,"url":"https://github.com/nventive/dotnet.backend.template","last_synced_at":"2025-04-13T00:14:43.443Z","repository":{"id":37801545,"uuid":"198429932","full_name":"nventive/DotNet.Backend.Template","owner":"nventive","description":".NET Core Templates for backend applications and open-source components.","archived":false,"fork":false,"pushed_at":"2023-11-02T14:42:23.000Z","size":489,"stargazers_count":7,"open_issues_count":6,"forks_count":3,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-04-13T00:14:37.440Z","etag":null,"topics":["aspnetcore","azure-functions","csharp","dotnet-core","dotnet-template","graphql"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nventive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-23T12:51:47.000Z","updated_at":"2024-05-22T18:32:39.000Z","dependencies_parsed_at":"2023-01-25T07:46:28.563Z","dependency_job_id":"e9624fcb-335a-440c-9e76-9b2ab25b3140","html_url":"https://github.com/nventive/DotNet.Backend.Template","commit_stats":null,"previous_names":["nventive/nv.templates"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FDotNet.Backend.Template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FDotNet.Backend.Template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FDotNet.Backend.Template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nventive%2FDotNet.Backend.Template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nventive","download_url":"https://codeload.github.com/nventive/DotNet.Backend.Template/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647274,"owners_count":21139086,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aspnetcore","azure-functions","csharp","dotnet-core","dotnet-template","graphql"],"created_at":"2024-11-26T04:11:49.309Z","updated_at":"2025-04-13T00:14:43.421Z","avatar_url":"https://github.com/nventive.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DotNet.Backend.Template\n\n.NET Templates for backend applications and open-source components.\n\nThis project provides templates that include backed-in patterns and best practices based on experience of implementing many solutions using Microsoft technologies.\n\nGenerated projects can:\n- Build a Web project that exposes a REST API, a GraphQL API, host a SPA application, run in Azure Functions or as a command-line application\n- Create netstandard OSS components published on NuGet/GitHub\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)\n[![Build Status](https://dev.azure.com/nventive-public/nventive/_apis/build/status/nventive.NV.Templates?branchName=master)](https://dev.azure.com/nventive-public/nventive/_build/latest?definitionId=6\u0026branchName=master)\n![Nuget](https://img.shields.io/nuget/v/NV.Templates.svg)\n\n## Getting Started\n\n### Prerequisites\n\n- Install the [.NET Core SDK](https://dotnet.microsoft.com/download)\n\n- Install the templates locally\n```shell\ndotnet new -i NV.Templates\n```\n\n### Generate a Backend project\n\nRun the template with the relevant options:\n```shell\ndotnet new nv-backend -n \u003cproject name\u003e -C \u003ccompany name\u003e [options]\n```\n\nBy default, the project will only generate a `Core` library to host the\ncore business logic of the application.\nTo generate suitable hosts to run and expose it, use the following options:\n\n| Option      | Description                                                           |\n|-------------|-----------------------------------------------------------------------|\n| --RestApi   | Generates an ASP.NET Core MVC project suitable for exposing REST APIs |\n| --SPA       | Generates an ASP.NET Core project suitable for hosting SPAs           |\n| --Functions | Generates an Azure Functions project                                  |\n| --Console   | Generates a Console (command-line) project                            |\n| --Auth      | Add authentication (JWT-based) support in Web projects                |\n| --Azure     | Add Azure ARM Template and DevOps Pipeline                            |\n\nOptions can be combined, e.g.\n```shell\ndotnet new nv-backend -n \u003cproject name\u003e -C \u003ccompany name\u003e --RestApi --SPA --Functions --Console --Auth\n```\n\nFor more details on each project type, see the [Features / Backend](#backend) section.\n\n### Generate a netstandard Component project\n\nRun the template:\n```shell\ndotnet new nv-netstandard-component -n \u003ccomponent name\u003e -C \u003ccompany name\u003e\n```\n\nFor more details on what's provided, see the [Features / Component](#component) section.\n\n## Features\n\n### Backend\n\n#### Core\n\nRegardless of the options provided to the template, there is always 2 projects\nthat are generated: `Core` and `Core.Tests`, along with some supporting solution files.\n\nHere is the set of feature provided as part of the Core feature set:\n\n- `Core`: a `netstandard2.0` library where the business logic of the application\nis meant to reside. Contains:\n  - `IApplicationInfo` / `ApplicationInfo` service that represents the execution\n    environment of the application itself\n  - `IOperationContext` / `OperationContext` service that represents a the execution\n    environment of a single operation executed by the library; it is meant to be\n    registered as a *Scoped* service, and the lifetime of it must be managed by the\n    Dependency Injection container\n  - Various interfaces and base classes for Entity-type class (in the `Framework` namespace) \n  - an `IdGenerator` utility class to generate unique ids as reasonably readable strings\n  - Inclusion of helpers and extension methods to handle pagination as Continuation tokens\n    (in `Framework/Continuation`) as the preferred method to handle pagination\n    (as opposed to offset pagination)\n  - A set of standard, application-level `Exception` classes to handle common cases\n    (`ConcurrencyException`, `DependencyException`, `NotFoundException`)\n  - An extension method to help registering all services in the Dependency Injection\n    container (in `ServiceCollectionExtensions`)\n  - A set of attributes that helps with auto-registration of services (see the `OperationContext` class for an example)\n  - Http Dependencies support with the help of `Refit`: all `HttpClient` options are standardized and `Polly` parameters are applied\n\n- `Core.Tests`: a [xUnit](https://xunit.net/) project for unit-tests. Contains:\n  - `OptionsHelper` to help load [Options](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-3.1) from unit-tests projects configuration\n  - `EntityFactory` to help implement the [Object Mother](https://martinfowler.com/bliki/ObjectMother.html) unit testing pattern\n  - An adapter that adapts a `ILogger` to the standard xUnit output\n\n- Solution Items files: Various solution files that apply to all projects:\n  - an [.editorconfig](https://editorconfig.org/) configuration file\n  - standard configuration for [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) and [FxCop](https://github.com/dotnet/roslyn-analyzers) that applies to all projects in the solution\n  - common set of properties for all projects (in `Directory.Build.props`)\n  - all projects are marked with a property named `TemplateVersion` that is set\n    to the template version used during project generation\n  - a Powershell script to generate an `ATTRIBUTIONS.txt` file to collect all\n    NuGet packages license information to ensure compliance\n\n*Implementation Get Started*\n\n- Create the relevant service interfaces and implementations; services can be annotated with `[RegisterXXXService]` attributes to be auto-registered in Dependency Injection\n- Create the corresponding unit tests in the `Core.Tests` project\n\n*Using the library*\n\nIn order to use the library in the context of an application, it needs to be setup\nin a specific way. While the template options for head projects provide such an\nenvironment, if you need to do it yourself here is what's needed:\n\n- [Create a .NET Host](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-3.1)\n- Configure the library by adding the library services using the `IServiceCollection.AddCore` extension method\n- Ensure that each operation is executed in a separate scope\n  (e.g. by using [`IServiceProvider.CreateScope`](https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.serviceproviderserviceextensions.createscope?view=dotnet-plat-ext-3.1))\n\n\n#### RestApi\n\nWhen using the `--RestApi` option, 2 projects are added to the solution:\n\n- `Web`: An ASP.NET Core application setup for exposing the Core library as a Rest API. Contains the following features:\n  - MVC bootstrap code with API-related features\n  - JSON options configured with sensible default\n  - [ASP.NET Core API Versioning](https://github.com/microsoft/aspnet-api-versioning) is\n    enabled and setup with support for versioning of the API in the URL (e.g. `/api/v1/...`)\n  - [Application Insights](https://docs.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview) is configured\n  - HTTPS is enforced and [HSTS](https://fr.wikipedia.org/wiki/HTTP_Strict_Transport_Security) is configured\n  - [CORS](https://developer.mozilla.org/en-us/docs/Web/HTTP/CORS) is configured\n  - Full request and response tracing is available, courtesy of the `AspNetCoreRequestTracing` component\n  - Generic error handling middleware is already setup (in `Framework.Middleware.ExceptionHandler`)\n    and configured for the exception classes provided in the Core project\n  - HTTP Response caching is configured to return \"no-store,no-cache\" by default\n  - Swagger/Open API support is configured, courtesy of [NSwag](https://github.com/RicoSuter/NSwag)\n  - `/attributions.txt` handler configured, to expose the `ATTRIBUTIONS.txt` file\n    the includes 3rd-party NuGet licenses\n  - `/api/info` endpoint that exposes `IApplicationInfo` information\n  - [ASP.NET Core health checks](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-3.1) are configured, with additional tracing options exposed through a `/health` endpoint\n  - Models that maps with the Continuation tokens classes defined in `Core`\n  - all operations return a `X-OperationId` header with the current `IOperationContext.Id` value\n  - errors include an additional Help Desk Id property, courtesy of the `HelpDeskId` component\n\n- `Web.Tests`: a [xUnit](https://xunit.net/) [integration tests](https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-3.1) project.\n  Sets up a `TestWebApplicationFactory` and a xUnit collection for tests that \n  automatically starts an in-memory instance of the ASP.NET Core application.\n\n#### SPA\n\nWhen using the `--SPA` option, the `Web` project is augmented with the following features:\n\n- Adds support for ASP.NET Core SPA Services, with on-the-fly compilation and hot-reload when developing and serving the statically compiled app when hosting in production\n- Creates a `ClientApp` folder that should host the content of the SPA; it is voluntarily left empty\n\nOnce 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](https://create-react-app.dev/) or [Angular CLI](https://cli.angular.io/)).\n\n#### Auth\n\nWhen using the `--Auth` option, the `Web` project is augmented with the following features:\n\n- Adds support for validating JWT tokens\n- Configuration is achieved via options; an example is given in `LocalSettings.Development.json`\n- Integration with RestApi\n- Integration with the `IOperationContext`\n- Integration with the Application Insights Telemetry\n- Adds support for OAuth2 login in Open API\n\nCovering the entire scope of authentication and authorization is too large for this documentation.\nThis option is only there to provide a starting point.\nPlease refer to the [ASP.NET Core documentation](https://docs.microsoft.com/en-us/aspnet/core/security/?view=aspnetcore-3.1) for more info.\n\n#### Azure Functions\n\nWhen using the `--Functions` option, 2 projects are added to the solution:\n\n- `Functions`: an Azure Functions project\n  - Azure Functions setup with [integrated Dependency Injection](https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection)\n  - Support for scoped execution is [provided by the Azure Functions SDK](https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection#service-lifetimes)\n\n\n- `Functions.Tests`: a [xUnit](https://xunit.net/) project for unit testing the functions\n\n#### Console app\n\nWhen using the `--Console` option, 2 projects are added to the solution:\n\n- `Console`: a .NET Core console application\n  - Organized around the Command pattern using [`CommandLineUtils`](https://github.com/natemcmaster/CommandLineUtils)\n  - Sets up a Generic Host with integrated Dependency injection\n  - Each command is a separate class, with argument parsing\n\n- `Console.Tests`: a [xUnit](https://xunit.net/) project for unit testing the commands\n\n#### Azure\n\nWhen using the `--Azure` option, an [Azure Resource Manager template](https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/) is added to the solution.\n\nTo deploy the infrastructure, please install the [Azure CLI](https://docs.microsoft.com/en-us/cli/azure) and run the following commands:\n\n```bash\n$ az group create -l \u003cResource Group Location\u003e -n \u003cName of the Resource Group\u003e\n$ az deployment group create --resource-group \u003cName of the Resource Group\u003e --template-file azure.azrm.json --parameters projectName=\u003cProject Name\u003e environment=\u003cEnvironment\u003e billTo=\u003cDept or Individual\u003e managedBy=\u003cDept or Individual\u003e\n```\ne.g.\n```bash\n$ az group create -l canadacentral -n MyAwesomeApp.QA\n$ 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\n```\n\nThe template has many parameters documented, but here is a few items included:\n- [App Configuration](https://docs.microsoft.com/en-us/azure/azure-app-configuration/)\n- [App Service](https://docs.microsoft.com/en-us/azure/app-service/) with auto-scaling and staging slots\n- [Function App](https://docs.microsoft.com/en-us/azure/azure-functions/)\n- [Application Insights](https://docs.microsoft.com/en-us/azure/azure-monitor/)\n\nAlso, an Azure DevOps build pipeline is included to get started faster. This is intended to be a starting point\nmore than a turn key solution though.\n\n### NetStandard Component\n\nProvides a base repository, solution and projects to create an open-source component.\n\nIncludes:\n\n- an [.editorconfig](https://editorconfig.org/) configuration file\n- 2 projects:\n  - a `netstandard2.0` library for the component\n  - a [xUnit](https://xunit.net/) project for unit testing\n- standard configuration for [StyleCop](https://github.com/DotNetAnalyzers/StyleCopAnalyzers) and [FxCop](https://github.com/dotnet/roslyn-analyzers) that applies to all projects in the solution\n- common set of properties for all projects (in `Directory.Build.props`)\n- all projects are marked with a property named `TemplateVersion` that is set\n  to the template version used during project generation\n- default `azure-pipeline.yml` CI build file, along with an adequate [GitVersion](https://gitversion.readthedocs.io) configuration\n- standard supporting file for GitHub-published components:\n  - a default `README.md` file\n  - a [`CHANGELOG.md`](https://keepachangelog.com) file\n  - default GitHub Issue and Pull Requests templates\n  - an Apache-2.0 `LICENSE` file\n  - a [Contributor Covenant Code of Conduct](https://www.contributor-covenant.org/)\n  - instructions regarding contributions\n\n## Changelog\n\nPlease consult the [CHANGELOG](CHANGELOG.md) for more information about version\nhistory.\n\n## License\n\nThis project is licensed under the Apache 2.0 license - see the\n[LICENSE](LICENSE) file for details.\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on the process for\ncontributing to this project.\n\nBe mindful of our [Code of Conduct](CODE_OF_CONDUCT.md).\n\n## Acknowledgments\n\n- [Dotnet-Boxed Templates](https://github.com/Dotnet-Boxed/Templates)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventive%2Fdotnet.backend.template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnventive%2Fdotnet.backend.template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnventive%2Fdotnet.backend.template/lists"}