CleanerSharpApi 0.1.0-alpha

This is a prerelease version of CleanerSharpApi.
dotnet add package CleanerSharpApi --version 0.1.0-alpha
                    
NuGet\Install-Package CleanerSharpApi -Version 0.1.0-alpha
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CleanerSharpApi" Version="0.1.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanerSharpApi" Version="0.1.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="CleanerSharpApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CleanerSharpApi --version 0.1.0-alpha
                    
#r "nuget: CleanerSharpApi, 0.1.0-alpha"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CleanerSharpApi@0.1.0-alpha
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CleanerSharpApi&version=0.1.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CleanerSharpApi&version=0.1.0-alpha&prerelease
                    
Install as a Cake Tool

<img src="logo.png" alt="Logo" width="400" style="display:block; margin:auto;"> <hr>

CleanerSharpApi

CleanerSharpApi is a clean architecture C# library for building maintainable APIs following SOLID and RESTful principles. It provides a structured approach to CRUD operations with clear separation between data access (Repository), business logic (Entity Service), and request handling (Endpoint).

Architecture

The Architecture of the library consists of 3 Main parts or layers which are :

1- Repository

2- Service

3- Endpoint

and in the main architecture of the API those layers should be the most inner layers of the API after all the Authentication and authorization and any other checks that are general to request and do not care about the specifics and internal details of the request

Figure 1

graph LR
    A[Api pipeline]:::stage --> B[Endpoint]:::stage
    B --> C[Service]:::stage
    C --> D[Repository]:::stage
    D --> E[Storage]:::stage

Keep in mind that internally the library is designed as a bunch of base interfaces and you'll find that the Repository , EntityService and Endpoint interfaces all inhirate the same ICrud interface and don't add anything extra and that is right. it's just to give a base for applying the architecture cleanly and differentiate between different responsibilities

every interface in this library inhirates from some Action interface and all Action interfaces describe different actions and there are 4 different classes of actions

1- Synchronous Crud Actions: represented in the ICrud interface which represent the basic CRUD actions as Create,Read,Update and Delete

public interface ICrud<
    TCreateResult,
    TCreateInput,
    TReadResult,
    TReadQuery,
    TUpdateResult,
    TUpdateQuery,
    TUpdateInput,
    TDeleteQuery
>
    : ICreate<TCreateResult, TCreateInput>,
        IRead<TReadResult, TReadQuery>,
        IUpdate<TUpdateResult, TUpdateQuery, TUpdateInput>,
        IDelete<TDeleteQuery> { }

2- Asynchronous Crud Actions: represented in the ICrudAsync interface which represent an asynchronous version of the basic CRUD actions as CreateAsync,ReadAsync,UpdateAsync and DeleteAsync

public interface ICrudAsync<
    TCreateResult,
    TCreateInput,
    TReadResult,
    TReadQuery,
    TUpdateResult,
    TUpdateQuery,
    TUpdateInput,
    TDeleteQuery
>
    : ICreateAsync<TCreateResult, TCreateInput>,
        IReadAsync<TReadResult, TReadQuery>,
        IUpdateAsync<TUpdateResult, TUpdateQuery, TUpdateInput>,
        IDeleteAsync<TDeleteQuery> { }

3- Synchronous Crud-Many Actions: represented in the ICrudMany interface which represent basic CRUD actions on a list of entities in CreateMany, ReadMany, UpdateMany and DeleteMany

public interface ICrudMany<
    TCreateResult,
    TCreateInput,
    TReadResult,
    TReadQuery,
    TUpdateResult,
    TUpdateQuery,
    TUpdateInput,
    TDeleteQuery
>
    : ICreateMany<TCreateResult, TCreateInput>,
        IReadMany<TReadResult, TReadQuery>,
        IUpdateMany<TUpdateResult, TUpdateQuery, TUpdateInput>,
        IDeleteMany<TDeleteQuery> { }

4- Asynchornous Crud-Many Actions: represented in the ICrudManyAsync interface which represent basic CRUD actions on a list of entities asynchronously in the actions CreateManyAsync, ReadManyAsync, UpdateManyAsync and DeleteManyAsync

public interface ICrudManyAsync<
    TCreateResult,
    TCreateInput,
    TReadResult,
    TReadQuery,
    TUpdateResult,
    TUpdateQuery,
    TUpdateInput,
    TDeleteQuery
>
    : ICreateManyAsync<TCreateResult, TCreateInput>,
        IReadManyAsync<TReadResult, TReadQuery>,
        IUpdateManyAsync<TUpdateResult, TUpdateQuery, TUpdateInput>,
        IDeleteManyAsync<TDeleteQuery> { }

Rules

Please make sure to follow this set of rules:

1- Returning a value always means Success even if it was Null, a Failure should be represented as an Exception

2- Exceptions can be thrown at any part of the pipeline indicating safe failure

3- Always keep each implementation Isolated focused on it's own responsibility regardless of others

4- Always make sure to follow the SOLID principles and make RESTful Apis , the library is designed for that anyway

5- Always try not to skip , follow the pipeline even if that layer is just a pass through adding no value to the pipeline

6- Repositories will always be Wrappers around an actual storage system either EF core or any other storage out there you are planning to use in your Api

7- Always be minimal , don't try to handle every case just a generic or specific version of your own case

These are a set of rules to make sure you always write clean and readable code

Responsibilities

Repository

The Repository's responsibility is all about communicating to the Storage fetching the data and storing it in the appropriate way and format.

Service

The Service's responsibility is all about business logic and entity-specific logic weather it's accessibility or processing

Endpoint

The Endpoint's responsibility is all about the request and response where it calls the correct functions to performe the user's specified request and return the appropriate response

Note: Each of the layers can consist of multiple internal layers on the inside depending on your use case

Examples

Honstly the example would take

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
0.1.0-alpha 117 9/9/2025