KerolosAmin.CleanArchitectureApi.Templates
1.0.1
See the version list below for details.
dotnet new install KerolosAmin.CleanArchitectureApi.Templates::1.0.1
Template For Clean Architecture And Repository Pattern
This template provides a robust structure for building scalable applications using Clean Architecture and the Repository Pattern. The project is organized into several layers to promote separation of concerns, maintainability, and testability.
🏗️ Project Structure
Template.Domain
- Entities: Core business models are defined here. This layer represents the heart of the application and contains business rules that are independent of any external systems like databases or APIs.
- Dependencies: Shared classes or utilities that are used across the domain layer.
Template.Application
- RepositoryInterfaces: Defines interfaces for repositories used for accessing data. Each entity in the Domain layer will have a corresponding repository interface in this layer.
- Services: Contains application logic and use cases. This layer acts as a mediator between the presentation/UI layer and the domain layer.
- DTO (Data Transfer Objects): Classes that are used to pass data between layers.
- ConstantOrEnum: Definitions of constants and enumerations used across the application.
Template.Infrastructure
- RepositoryImplementation: Concrete implementations of the repository interfaces declared in the Application layer. This is where the actual database operations occur, utilizing Entity Framework Core or other ORM frameworks.
- Data: Database context and configurations for working with data.
- Migrations: Database migrations for managing schema changes over time.
- Dependencies: Shared classes or utilities required by the infrastructure layer.
Template.Web
- Web Project: The entry point for the application. This project hosts the API, handles HTTP requests, and connects the Application layer with the outside world.
🧩 Repository Pattern
The project contains a generic repository interface IBaseRepository<T> that provides basic CRUD operations:
- GetById(int id)
- GetAll()
- Add(T entity)
- Update(T entity)
- Delete(T entity)
→ Additional Features: Asynchronous versions of the basic methods: GetByIdAsync, GetAllAsync, AddAsync, etc. Support for filtering data with Find() and FindAsync() methods that accept expressions.
→ Range operations like AddRange and DeleteRange for bulk data handling.
→ Count operations to retrieve data counts from the repository.
✨ Key Features
Repository Pattern Implementation
Generic IBaseRepository<T> interface
- Async CRUD operations
- Specification pattern support
- Unit of Work implementation
- Clean Architecture Benefits
- Clear separation of concerns
- Independent domain layer
- Testable architecture
- Flexible infrastructure
- Included Infrastructure
- Entity Framework Core setup
- JWT Authentication ready
- Swagger/OpenAPI configured
- Serilog logging
- Health checks
- API versioning
- Global exception handling
🔧 Getting Started
Prerequisites .NET Core SDK Entity Framework Core
Step 1: Install the Template
dotnet new install CleanArchitecture.Template
- Step 2: Create a New Project
dotnet new ca-template -n YourProjectName -o YourProjectName
cd YourProjectName
- Step 3: Configure Database
Open src/YourProjectName.Web/appsettings.json
Replace the connection string:
json "ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=YourProjectDb;User Id=sa;Password=YourPassword;TrustServerCertificate=True;" }
- Step 4: Apply Database Migrations
dotnet ef database update --project src/YourProjectName.Infrastructure
- Step 5: Run the Application
dotnet run --project src/YourProjectName.Web
for later update template use this command
dotnet new update
🏗️ Clean Architecture Overview
- Domain Layer: Contains business entities and interfaces, ensuring that core business logic is independent of external dependencies.
- Application Layer: Manages application logic, use cases, and interacts with the domain through services and repositories.
- Infrastructure Layer: Contains implementation details, such as database connections, external services, and repository implementations.
- Web Layer: Hosts the API or UI, connects users or external systems to the application.
⚙️ Customizing the Template
Adding New Entities:
Create new entity classes in the Domain.Entities folder.
Define the repository interface for the entity in Application.RepositoryInterfaces.
Implement the repository in Infrastructure.RepositoryImplementation.
Extending the Repository: You can add more methods to the IBaseRepository<T> or create specific repositories for entities as needed.
4. Update the appsettings.json and Other Configuration Files
- Open appsettings.json and other configuration files to ensure that any project-specific paths or references are updated with the new project name.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.