KerolosAmin.CleanArchitectureApi.Templates 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet new install KerolosAmin.CleanArchitectureApi.Templates::1.0.1
                    
This package contains a .NET Template Package you can call from the shell/command line.

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

  1. 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.
  2. 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.
  3. 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.
  4. 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
  1. Async CRUD operations
  2. Specification pattern support
  3. Unit of Work implementation
  4. Clean Architecture Benefits
  5. Clear separation of concerns
  6. Independent domain layer
  7. Testable architecture
  8. Flexible infrastructure
  9. Included Infrastructure
  10. Entity Framework Core setup
  11. JWT Authentication ready
  12. Swagger/OpenAPI configured
  13. Serilog logging
  14. Health checks
  15. API versioning
  16. Global exception handling

🔧 Getting Started

  1. Prerequisites .NET Core SDK Entity Framework Core

  2. Step 1: Install the Template

dotnet new install CleanArchitecture.Template
  1. Step 2: Create a New Project
dotnet new ca-template -n YourProjectName -o YourProjectName
cd YourProjectName
  1. 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;" }

  1. Step 4: Apply Database Migrations
dotnet ef database update --project src/YourProjectName.Infrastructure
  1. 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

  1. Adding New Entities:

  2. Create new entity classes in the Domain.Entities folder.

  3. Define the repository interface for the entity in Application.RepositoryInterfaces.

  4. Implement the repository in Infrastructure.RepositoryImplementation.

  5. 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.

Version Downloads Last Updated
1.0.2 296 6/10/2025
1.0.1 149 9/23/2024
1.0.0 162 9/23/2024