EMH.Templates.MVCAPI 1.0.12

dotnet new install EMH.Templates.MVCAPI@1.0.12
                    
This package contains a .NET Template Package you can call from the shell/command line.

๐Ÿงฉ Templates ยท MVC API Project Template

A dotnet new template for ASP.NET Core MVC APIs that shows the Email Hippo project layout and coding standards.

.NET NuGet Swagger License

This repo looks legacy/inactive. The template targets .NET 10 (retargeted from .NET Core 3.1 in November 2026).


โœจ What it does

The repo is packed as the NuGet template package EMH.Templates.MVCAPI (short name emh-webapi). The src/ folder is the template content: a working web API with a "Hello World" demo that runs through every tier.

flowchart LR
    C["Client"]
    HC["HelloWorldController<br/>api/helloworld/v1"]
    S["HelloWorldService<br/>(service tier)"]
    M["Mappers<br/>(SimpleMapper)"]
    P["HelloWorldProcessor<br/>(biz tier, MemoryCache)"]
    R["HelloWorldReadOnlyRepository<br/>(retry policy, fake data)"]

    C --> HC --> S
    S --> M
    S --> P --> R
Tier Example Purpose
Host HelloWorldController Validates input, calls the service tier, returns JSON, XML, BSON or protobuf
Service tier HelloWorldService Maps service DTOs to biz DTOs and back; wraps the call in the IExceptionProcessor log-and-resume policy
Biz tier HelloWorldProcessor Business logic; caches repository data in a MemoryCache for 10 minutes
Repository HelloWorldReadOnlyRepository Data access stand-in; returns two hard-coded rows inside an exponential-backoff retry policy

Other things the template sets up: SimpleInjector DI, Serilog with the HippoLog adapter, security headers (NetEscapades.AspNetCore.SecurityHeaders), an allow-all CORS policy, Swagger UI, and StyleCop analyzers.


๐Ÿ“ฆ Using this template

1. Install the template

dotnet new --install EMH.Templates.MVCAPI

2. Create a project from it

dotnet new emh-webapi -n {YourProjectName}

The template's sourceName is EMH.MVCAPI.Host.Web, so -n replaces that string. Then look for the // TODO: comments in Startup.cs (API name, Swagger description, your DI registrations) and remove the demo registrations.


๐Ÿš€ Quick start (working on the template itself)

Prerequisites

  • .NET 10 SDK (the tests and the host run on the .NET 10 runtime).
  • All packages, including EMH.Lib.Patterns.*, restore from nuget.org.

Build, test, run

cd src
dotnet build EMH.MVCAPI.sln
dotnet test EMH.MVCAPI.sln

cd Hosts/EMH.MVCAPI.Host.Web
dotnet run

Run a single test class:

dotnet test --filter "FullyQualifiedName~HelloWorldProcessorTests"

๐Ÿ”Œ API

Method Route Description
GET / Returns Email Hippo API.
GET /api/helloworld/v1/getmessage/{query} Demo endpoint. query must be 1โ€“255 chars. Returns a HelloWorldResult (Message, Error)
GET /swagger/v1/swagger.json OpenAPI document (serialised as Swagger 2.0)
GET /swagger Swagger UI

The demo endpoint ignores query and always fetches item 1. Responses can be JSON, XML, BSON (application/bson) or protobuf (application/x-protobuf).


๐Ÿงช Testing

Suite Location Needs
Unit src/Tests/EMH.MVCAPI.Biz.Tests/BizTier/Unit, Core/Helpers Nothing
Integration src/Tests/EMH.MVCAPI.Biz.Tests/BizTier/Integration Nothing today (the repository uses fake data)

Tests use NUnit and Moq. TestBase sets up Serilog/HippoLog, an exception processor, and config from appsettings.json, environment variables and (Debug only) user secrets.


โš™๏ธ Configuration

Settings come from appsettings.json, overlaid by appsettings.{Environment}.json and environment variables (standard ASP.NET Core host defaults).

Key Description
AppConfiguration:Setting1 / Setting2 Example settings, bound to AppConfiguration and registered as a singleton
Serilog Serilog sinks and minimum level (console sink by default)
Logging:LogLevel Microsoft logging levels
AllowedHosts Host filtering (*)

๐Ÿ—‚๏ธ Project layout

build/
โ”œโ”€โ”€ EMH.MVCAPI.nuspec          Template package definition (EMH.Templates.MVCAPI)
โ”œโ”€โ”€ pack.csproj                Packs the nuspec with dotnet pack (nothing compiled)
โ””โ”€โ”€ icon.png                   Package icon
src/
โ”œโ”€โ”€ .template.config/          dotnet new metadata (short name emh-webapi)
โ”œโ”€โ”€ Business/EMH.MVCAPI.Biz/   netstandard2.0: service tier, biz tier, repos, mappers, helpers
โ”œโ”€โ”€ Hosts/EMH.MVCAPI.Host.Web/ net10.0 web host: Startup, controllers, BSON/protobuf formatters
โ”œโ”€โ”€ Tests/EMH.MVCAPI.Biz.Tests/ NUnit + Moq tests
โ””โ”€โ”€ EMH.MVCAPI.sln
bitbucket-pipelines.yml        Pack and publish on release tags

๐Ÿ” CI/CD

Bitbucket Pipelines (bitbucket-pipelines.yml) runs only on tags matching release-*. There is no build or test step for branches or PRs.

  1. Copies src/ to publish/content/, and the nuspec, build/pack.csproj and README.md to publish/.
  2. Packs EMH.Templates.MVCAPI with dotnet pack (.NET 10 SDK) at version 1.0.<build number>.
  3. Publishes it to nuget.org through the shared emailhippo/nuget-publisher script (no API key in this repo).

The package is published to the public nuget.org feed. Anything in src/ ends up in it.


<sub>ยฉ Email Hippo Ltd</sub>

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.12 0 11/28/2026
1.0.10 3,292 7/14/2020
1.0.9 1,157 7/14/2020
1.0.8 1,361 9/2/2019
1.0.7 1,504 3/25/2019
1.0.6 1,370 2/25/2019
1.0.5 1,413 2/15/2019
1.0.4 1,721 10/9/2018
1.0.3 1,579 9/29/2018

Initial commit.