项目作者: ludojmj

项目描述 :
.NET Core WebApi
高级语言: C#
项目地址: git://github.com/ludojmj/boilerwebapicore.git
创建时间: 2017-02-17T10:58:25Z
项目社区:https://github.com/ludojmj/boilerwebapicore

开源协议:MIT License

下载


boilerwebapicore

.NET Core 2.0 WebApi

  • Self Hosted: BoilerWebApiCore project
    1. $ git clone https://github.com/ludojmj/boilerwebapicore.git
    Architecture:
    1. $ dotnet new webapi -n MyApp
    2. $ dotnet new xunit -n MyApp.UnitTest

Visual Studio Code:

  1. $ code boilerwebapicore

Restore packages when asked by vscode then F5 to debug.

Alternatively with the command line:

  1. $ cd BoilerWebApiCore.UnitTest
  2. $ dotnet restore
  3. $ dotnet build
  4. $ dotnet test
  5. $ cd ../BoilerWebApiCore
  6. $ export ASPNETCORE_ENVIRONMENT=Development
  7. $ dotnet run
  • Front-end code:

    • BoilerWebApiCore/wwwroot/index.html + index.js + index.css
  • Back-end code:

    • BoilerWebApiCore/Controllers/ProductController.cs
    • BoilerWebApiCore/Controllers/OtherProductController.cs
  • Automatic logs settings:

    • BoilerWebApiCore/appsettings.json

Swagger

Layers

BoilerWebApiCore/wwwroot

  • index.html
  • index.js
  • index.css

BoilerWebApiCore/Controllers

  • ProductController businessError=1 => KO

    • api/product?businessError=1

      ==> GET KO (intentional BoilerWebApiCore.BusinessException)

    • api/product/async?businessError=1

      ==> GET KO (intentional BoilerWebApiCore.BusinessException)

  • ProductController businessError=0 => OK

    • api/product?businessError=0

      ==> GET OK

    • api/product/async?businessError=0

      ==> GET OK

  • OtherProductController input.Name=”1” => KO

    • api/otherproduct { Name = “1”, … }

      ==> POSTT KO (unintentional System.DivideByZeroException)

    • api/product/async { Name = “1”, … }

      ==> POST KO (unintentional System.DivideByZeroException)

  • OtherProductController input.Name=”0” => OK

    • api/product { Name = “0”, … }

      ==> POST OK

    • api/product/async { Name = “0”, … }

      ==> POST OK

  • ErrorController

    • api/error

      ==> Generic message displayed because of a bug in application

BoilerWebApiCore/Repository

  • IProductRepo.cs
  • IOtherProductRepo.cs

  • ProductRepo.cs

  • OtherProductRepo.cs

BoilerWebApiCore/Models

  • Product.cs
  • ErrorContent.cs

BoilerWebApiCore/Shared

  • BusinessException.cs : Exception

    ==> Voluntary BusinessException thrown wherever in application in order to display a business message to user

  • GenericExceptionHandler : IExceptionFilter

    ==> Displaying a business message to user in case of BusinessException (MVC)

    ==> Delegating logging and displaying a generic message in ErrorController (AspNet)