Skip to content

ik-dotnet/AspNetCoreApiStarter

Repository files navigation

CodeStream AspNetCoreApiStarter

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)

Build status

Deployed instance of API

https://codestreamaspnetcoreapistarter.azurewebsites.net/swagger

Direct references to Frameworks:

Getting started

  • 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).

To repurpose for new API projects

  • 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
  • Run through Getting Started steps listed above
  • Find and Replace CodeStreamAspNetCoreApiStarter with Your 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 of appsettings.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.

LogDNA configuration and usage

MediatR Pipeline configuration and implementation

AutoMapper configuration

MediatR Pipeline logging with LogDNA

  • All Command and Query messages should inherit from AppMessage
  • All executions of Commands and Queries will be logged via LogDNAMediatrPipeline
  • Execution time in milliseconds will also be logged against the Command / Query

Command / Query chaining and CorrelationId

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.

Exception Handling & Logging

Global exception handling and logging happens in GlobalExceptionHandler and attempt to following RFC7807 as per this article.

Pipeline level exception handling happens in ErrorHandlerMediatrPipeline

About

ASP.NET Core WebApi Starter Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages