BookStore/ │ ├── src/ │ ├── BookStore.API/ (Presentation Layer) │ │ ├── Application/ │ │ │ └── Services/ │ │ │ └── BookService.cs │ │ ├── Controllers/ │ │ │ └── BooksController.cs │ │ ├── Models/ │ │ │ └── BookDto.cs │ │ ├── Validators/ │ │ │ └── BookDTOValidator.cs │ │ └── Program.cs (Entry point) │ │ │ ├── BookStore.Domain/ (Domain Layer) │ │ ├── AggregatesModel/ │ │ │ └── Books/ │ │ │ ├── Book.cs │ │ │ ├── IBookRepository.cs │ │ │ └── IBookService.cs │ │ └── Extensions/ (Extension methods) │ │ └── ServiceCollectionExtensions.cs │ │ │ ├── BookStore.Infrastructure/ (Infrastructure Layer) │ │ ├── ApplicationDbContext.cs │ │ ├── Repositories/ │ │ │ └── BookRepository.cs │ │ └── Extensions/ (Extension methods) │ │ └── ServiceCollectionExtensions.cs │ │ └── tests/ └── BookStore.Tests/ ├── Unit/ │ ├── Domain/ (Tests for Domain Layer) │ └── Infrastructure/ (Tests for Infrastructure Layer) │ └── Integration/ (Integration Tests)
dotnet new sln -n BookStore
dotnet new webapi -n BookStore.API -controllers -o src/BookStore.API dotnet new classlib -n BookStore.Domain -o src/BookStore.Domain dotnet new classlib -n BookStore.Infrastructure -o src/BookStore.Infrastructure dotnet new xunit -n BookStore.Tests -o tests/BookStore.Tests
dotnet sln add src/BookStore.API/BookStore.API.csproj dotnet sln add src/BookStore.Domain/BookStore.Domain.csproj dotnet sln add src/BookStore.Infrastructure/BookStore.Infrastructure.csproj dotnet sln add tests/BookStore.Tests/BookStore.Tests.csproj
- Domain Layer (BookStore.Domain): Define your domain entities and business logic. Start by implementing the Book class, representing the core entity in your application.
touch src/BookStore.Domain/Book.cs
- Infrastructure Layer (BookStore.Infrastructure): Implement the data access layer and database-related functionalities. Create the DbContext class, which represents your database context and defines the database schema. Implement repositories to interact with the database. Start by defining the interfaces (IBookRepository) and their implementations (BookRepository).
dotnet add src/BookStore.Infrastructure/BookStore.Infrastructure.csproj package Microsoft.EntityFrameworkCore.SqlServer
touch src/BookStore.Infrastructure/ApplicationDbContext.cs
mkdir src/BookStore.Infrastructure/Repositories touch src/BookStore.Infrastructure/Repositories/IBookRepository.cs touch src/BookStore.Infrastructure/Repositories/BookRepository.cs
- Application Layer (BookStore.Application): Implement the application services that orchestrate business logic and interact with the infrastructure layer. Create the IBookService interface, which defines the contract for operations related to books. Implement the BookService class, which provides the actual implementation of book-related operations using the repositories from the infrastructure layer.
mkdir src/BookStore.Application/Books touch src/BookStore.Application/Books/IBookService.cs touch src/BookStore.Application/Books/BookService.cs
- Presentation Layer (BookStore.API): Implement the API controllers and models. Create the BooksController class, which defines the API endpoints for managing books (e.g., CRUD operations). Define the BookDTO class, which represents the data transfer object used for transferring book-related data between the client and server.
dotnet add src/BookStore.API/BookStore.API.csproj package FluentValidation.AspNetCore
touch src/BookStore.API/Models/BookDTO.cs
mkdir src/BookStore.API/Controllers touch src/BookStore.API/Controllers/BooksController.cs