これは私の意見で、常に進行中の作業であるスターターテンプレートであり、レスト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を構築するときに行う必要があるすべての情報の流れを処理する私の方法として始まりました。覚えておくべきことはたくさんあり、膨大な量の選択肢があります。したがって、私はこのテンプレートを自分のために、私が実用的だと思ったすべてのプラクティスを保存するために作成しました。また、このテンプレートが他の誰かが1つまたは2つのことを学ぶのに役立つことを願っています。
このテンプレートでは、API構築に関する知識を実用的な形式で収集しました。ベストプラクティス、人気、私自身の意見の好みに基づいて、建築の好み、図書館の選択、その他の選択が行われます。このテンプレートの目的は、スケーラブルでマンテインが簡単で、必要な構成やその他のグッズを含むASP.NETを使用して、REST APIを構築する方法に関する優れた基本的な例を提供することです。このテンプレートは、Microsoft EshoponWebリファレンスアプリケーションおよびその他多くのものに触発されています。
このプロジェクトはMITライセンスを取得しています - とにかくお気軽に使用してください。提案と助けが歓迎されます。 ?