This is an application using a customer data model written with ASP.NET Core. There are several projects including REST apis, data models, middleware and an MVC front end. Many ASP.NET Core features are showcased and documented in the CustomersAPI project. The CustomersMVC project shows a few additional MVC-specific features.
Most code which relates to a particular feature area (configuration,
dependency injection, localization, logging, middleware, routing) has a
comment near it with the feature area as a keyword (like Middleware:
).
You can search for these keywords (or even view them in Visual Studio's
task list, by adding them to the token list at Tools > Options > Task List) to
find parts of the sample related to feature areas you'd like to see more
about.
This sample uses .NET Core 2.1. To build and run it, you will need the .NET Core SDK. You will also need an editor like Visual Studio 2017 or Visual Studio Code.
The docker-compose project requires Docker-for-Windows. If you will be using the docker-compose project, make sure Docker CE is installed on your development machine.
For more information on ASP.NET Core, see:
- official documentation, the
- ASP.NET team blog, or the
- GitHub repo
The code style requirements are enforced with
EditorConfig
via .editorconfig
and
StyleCop Analyzers via
CodeStyling.rulset
. As a general rule we "use Visual Studio defaults".
- We use Allman style braces, where each brace begins on a new line.
- We use four spaces of indentation (no tabs).
- We use
_camelCase
for internal and private fields and usereadonly
where possible. Prefix instance fields with_
, static fields withs_
and thread static fields witht_
. When used on static fields,readonly
should come afterstatic
(i.e.static readonly
notreadonly static
). - We avoid
this.
unless absolutely necessary. - We always specify the visibility, even if it's the default (i.e.
private string _foo
notstring _foo
). Visibility should be the first modifier (i.e.public abstract
notabstract public
). - Namespace imports should be specified at the top of the file, outside of
namespace
declarations and should be sorted alphabetically. - Avoid more than one empty line at any time. For example, do not have two blank lines between members of a type.
- Avoid spurious free spaces.
For example avoid
if (someVar == 0)...
, where the dots mark the spurious free spaces. Consider enabling "View White Space (Ctrl+E, S)" if using Visual Studio, to aid detection. - We use language keywords instead of BCL types (i.e.
int, string, float
instead ofInt32, String, Single
, etc) for both type references as well as method calls (i.e.int.Parse
instead ofInt32.Parse
). See issue 391 for examples. - We use PascalCasing to name all our constant local variables and fields. The only exception is for interop code where the constant value should exactly match the name and value of the code you are calling via interop.
- We use
nameof(...)
instead of"..."
whenever possible and relevant. - Fields should be specified at the top within type declarations.
- When including non-ASCII characters in the source code use Unicode escape sequences (\uXXXX) instead of literal characters. Literal non-ASCII characters occasionally get garbled by a tool or editor.
In order to enforce these styles, We use Directory.Build.props
and
Directory.Build.targets
files, which are imported implicitly by MSBuild
version 15.0 or later. More information can be found at MSBuild doc site
Customize your build