This is a starter project for building an ASP.NET Core WebApi project according to CodeStream opinions, tools and frameworks.
Built on top of ASP.NET Core 2.1.2 (as of 23 Jul 2018)
https://codestreamaspnetcoreapistarter.azurewebsites.net/swagger
- MediatR
- CodeStream.Mediatr
- CodeStream.LogDNA
- SimpleInjector
- AutoMapper
- FluentValidation
- Dapper
- EntityFramework Core
- NExtensions
- Swashbuckle (swagger / OpenApi)
- CI on AppVeyor (appveyor.yml)
- deployment to azure web app (via appveyor.yml)
- Clone (
git clone https://github.com/codestreamsystems/AspNetCoreApiStarter.git
) - Open in Visual Studio (Code)
- Build (
dotnet build
) - Run (
dotnet run
) and navigate to https://localhost:5001/swagger to inspect swagger documentation.
The app is hosted on https://localhost:5001 when launched from the command line using dotnet run
(using Kestrel) and hosted on https://localhost:44393 when launched from Visual Studio (using IIS Express).
- Fork/Clone this repo to your new project repo
- If you clone you will need to remove the default origin remote and add your own new remote origin with the following commands:
git remote remove origin
git remote add origin https://my.new.origin.url
- If you clone you will need to remove the default origin remote and add your own new remote origin with the following commands:
- Run through
Getting Started
steps listed above - Find and Replace
CodeStreamAspNetCoreApiStarter
withYour Shiny New Project Name
throughout all files in root project directory. - Rename the following files in the root directory accordingly:
- CodeStreamAspNetCoreApiStarter.sln
- CodeStreamAspNetCoreApiStarter.csproj
- Build (
dotnet build
) and Run (dotnet run
) to ensure no errors. - Update the
LogDNA
section ofappsettings.json
with the new relevant values. - Update
appveyor.yml
with relevant Azure publish profile settings of Azure app service you wish to deploy to. - Search for
TODO
comments that may instruct on specific replacements in code.
- For configuration see RegisterLogDNAServicesInSimpleInjector method in Startup.cs
- For usage see LogDNAMediatrPipeline
- For configuration see AppSimpleInjectorPackage
- For implementation see ErrorHandlerMediatrPipeline and LogDNAMediatrPipeline.cs
- For configuration see AutoMapperProfile
- All
Command
andQuery
messages should inherit from AppMessage - All executions of
Commands
andQueries
will be logged via LogDNAMediatrPipeline - Execution time in milliseconds will also be logged against the
Command / Query
In complex applications there will be the need for one Command / Query
to call another and so on creating a chain of messages (one calling the other). This results in multiple Commands / Queries
being called all in the scope of a single Http Request. When viewing logs of these Commands / Queries
is if often imperative to view all logs for all chained / linked messages. This can be done as long as all messages use the same CorrelationId
.
An example of this can be seen in the HeartBeatQueryHandler where the HeartBeatQueryHandler
executes the AppVersionQuery
.
Global exception handling and logging happens in GlobalExceptionHandler and attempt to following RFC7807 as per this article.
Pipeline level exception handling happens in ErrorHandlerMediatrPipeline