MyWebAPITemplate
1.0.0
这是我自以为是的,不断地正在进行的,开头模板,用于构建REST API。
如果您只想开始编码,想要一个已经经过深思熟虑的项目结构,这是非常简单且快速学习的,并且可以在较小和较大的项目上工作,则此模板适合您。
app -> App and related files
├─> src -> App source
│ ├─> Web -> Entry point for API - runnable project
│ │ ├─> Controllers -> API endpoints
│ │ ├─> Extensions -> Extension methods
│ │ ├─> Interfaces -> Web project's interfaces
│ │ ├─> Mappers -> Model mappers
│ │ ├─> Middlewares -> Middlewares (e.g. global error handling)
│ │ |─> Models -> Models in and out of API
│ │ ├─> Settings -> Options pattern for App (e.g. connection strings)
│ │ ├─> Validators -> Model validation rules
│ │ ├── Program.cs -> START
│ │ └── Startup.cs -> START
│ ├─> Core -> Holds business logic
│ │ ├─> Dtos -> Data-transfer-object (used for business logic)
│ │ ├─> Entities -> Entity Framework entities for database
│ │ ├─> Interfaces -> Core project's interfaces
│ │ ├─> Mappers -> Dto and Entity mappers
│ │ ├─> Services -> Business logic services
│ └─> Infrastructure -> Data access and external services
│ ├─> Database -> Database access
│ │ ├─> Configurations -> Entity Framework table configurations
│ │ ├─> Migrations -> Entity Framework autogenerated migrations
│ │ ├─> Repositories -> Repository pattern
│ │ ├── AppDbContext.cs -> Base context
│ │ ├── AppSeed.cs -> Database seeding
│ │ └── EfRepository.cs -> Base repository
│ └─> ExternalServices -> Services that access external services (e.g. ext. email service)
└─> tests -> App tests
├── FunctionalTests -> Endpoint tests etc.
│ ├─> Tests -> All tests
│ └─> Utils -> Utility functions (e.g. test database setup)
├── IntegrationTests -> Database tests etc.
│ ├─> Tests -> All tests
│ ├─> Utils -> Utilities functions (e.g. test database setup)
├── UnitTests -> Application logic tests etc.
│ ├─> Tests -> All tests
│ ├─> Utils -> Utility functions
└── Shared -> Model builders and other shared functions for tests
dotnet tool install --global dotnet-ef
dotnet ef database update -c ApplicationDbContext -p . /src/Infrastructure/Infrastructure.csproj -s . /src/Web/Web.csprojMyWebAPITemplate.sln打开F5或Debug/Start Debugging dotnet run -p . /src/Web/当您需要创建新的迁移(更改数据库架构时)时,请运行此命令以告诉实体框架以处理数据库所需的架构更改。
dotnet ef migrations add NewMigrationNameHere --context ApplicationDbContext -p . /src/Infrastructure/Infrastructure.csproj -s . /src/Web/Web.csproj -o Database /Migrations 该项目始于我处理以单一整体方式构建API时需要完成的一切信息流的方式。有很多事情要记住,还有很多选择。因此,我为自己制作了这个模板,以存储我发现实用的所有实践,我希望这个模板也可以帮助别人学习一两个东西。
在此模板中,我以实用格式收集了对API构建的知识。根据最佳实践,受欢迎程度和我自己的偏好,做出了建筑偏好,图书馆选择和其他选择。该模板的目的是提供一个很好的基本示例,介绍如何使用可扩展,易于使用的ASP.NET构建REST API,并包含必要的配置和其他好处。该模板的灵感来自Microsoft Eshoponweb参考应用程序和许多其他模板。
该项目已获得MIT许可 - 因此,无论如何都可以随意使用它。欢迎建议和帮助。 ?