一个简单而有组织的项目模板,用于在 .NET Core 3.1 中构建 ASP.NET Core API
A simple yet organized project template for building ASP.NET Core APIs using .NET Core 3.1 (the latest/fastest version of .NET Core to date) with preconfigured tools and frameworks. It features most of the functionalities that an API will have such as database CRUD operations, Token-based Authorization, Http Response format consistency, Global exception handling, Logging, Http Request rate limiting, HealthChecks and many more. The goal is to help you get up to speed when setting up the core structure of your app and its dependencies when spinning up a new ASP.NET Core API project. This enables you to focus on implementing business specific code requirements without you having to copy and paste the core structure of your project, common features, and installing its dependencies all over again. This will speed up your development time while enforcing standard project structure with its dependencies and configurations for all your apps.
If you are looking for a project template for ASP.NET Core API that you can reuse across your team, or if you are new to ASP.NET Core and would like to get up to speed on how it works without having you to configure most of the basic features that an API will have, then this is for you.
There are two ways to install the template:
Exceptions and consistent HTTP response format.Result attribute from AutoWrapper's ApiResponse output.JWT Authentication handlingHttpClient Resilience and Transient fault-handlingAPI based on IP address or client ID.Keep in mind that you can always replace and choose whatever framework you want to use for your API. After all, the template is just a skeleton for your project structure with default preconfigured middlewares. For example, you can always replace Dapper with Entity Framework Core, PetaPoco, etc. and configure them yourself. You can also replace Serilog with whatever logging frameworks and providers you want that works with ASP.NET Core - the choice is yours.
Here's the list of the good stuff that you can get when using the template:
Dapper.Serilog.AutoMapper for mapping entity models to DTOs.FluentValidation for DTO validations.AutoWrapper for handling request Exceptions and consistent HTTP response format.AutoWrapper.Server for unwrapping the Result attribute from AutoWrapper's ApiResponse output.Swagger API Documentation.CORS.JWT Authorization and Validation.Token.API documentation with Bearer Authorization.API Pagination.HttpClient Resilience and Transient fault-handling.Http Request Rate Limiter.HealthChecks and HealthChecksUI.xUnit.ApiBoilerPlate.dotnet new -i apiboilerplate.aspnetcore. This will install the template in your machine.dotnet new apiboilerplate --name "MyAPI" -o samples. This will generate the project template named MyAPI within the samples directory.Once installed, you should see the following console message:
The template "ASP.NET Core API Template for .NET Core 3.x" was created successfully.
Note: If you are using the previous version of the template, make sure to uninstall it first before you install the latest version.
Continue without code link.Extensions menu, click Manage Extensions.Online and then search for ApiBoilerPlate.Download. The extension is then scheduled for install.To complete the installation, close all instances of Visual Studio.
Alternatively, you can download and install the VSIX Extension directly at the following link: https://marketplace.visualstudio.com/items?itemName=vmsdurano.ApiProjVSExt
Create New Project boxApiBoilerPlate" in the search bar.ApiBoilerPlate item and then click Next.Create.STEP 1: Create a Test local Database:
View > SQL Server Object ExplorerSQL Server > (localdb)\MSSQLLocalDBDatabase" FolderAdd New Database"TestDB" and click OKTestDB" database and then select "New Query"Person" table.CREATE TABLE [dbo].[Person]
(
[Id] INT NOT NULL PRIMARY KEY IDENTITY(1,1),
[FirstName] NVARCHAR(20) NOT NULL,
[LastName] NVARCHAR(20) NOT NULL,
[DateOfBirth] DATETIME NOT NULL
)
STEP 2: Update Database ConnectionString (Optional)
If you follow step 1, then you can skip this step and run the application right away.
If you have a different database and table name then you need to change the connectionString in appsettings.json that is pointing to the newly created database. You can get the connectionString values in the properties window of the "TestDB" database in Visual Studio.
Feel free to request an issue on github if you find bugs or request a new feature. Your valuable feedback is much appreciated to better improve this project. If you find this useful, please give it a star to show your support for this project.
This project is licensed under the MIT License - see the LICENSE.md file for details.
If you find this project useful — or just feeling generous, consider buying me a beer or a coffee. Cheers! :beers: :coffee:
Thank you!
暂无开放 Issues,或尚未同步最近议题。