MasLazu.AspNet.Framework.Endpoint 1.0.0-preview.9

This is a prerelease version of MasLazu.AspNet.Framework.Endpoint.
dotnet add package MasLazu.AspNet.Framework.Endpoint --version 1.0.0-preview.9
                    
NuGet\Install-Package MasLazu.AspNet.Framework.Endpoint -Version 1.0.0-preview.9
                    
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="MasLazu.AspNet.Framework.Endpoint" Version="1.0.0-preview.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasLazu.AspNet.Framework.Endpoint" Version="1.0.0-preview.9" />
                    
Directory.Packages.props
<PackageReference Include="MasLazu.AspNet.Framework.Endpoint" />
                    
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 MasLazu.AspNet.Framework.Endpoint --version 1.0.0-preview.9
                    
#r "nuget: MasLazu.AspNet.Framework.Endpoint, 1.0.0-preview.9"
                    
#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 MasLazu.AspNet.Framework.Endpoint@1.0.0-preview.9
                    
#: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=MasLazu.AspNet.Framework.Endpoint&version=1.0.0-preview.9&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MasLazu.AspNet.Framework.Endpoint&version=1.0.0-preview.9&prerelease
                    
Install as a Cake Tool

MasLazu.AspNet.Framework

A modern, clean architecture ASP.NET Core framework built with .NET 9, designed for building scalable and maintainable web APIs.

🚀 Features

  • Clean Architecture: Strict separation of concerns with Domain, Application, Infrastructure, and Presentation layers
  • FastEndpoints Integration: High-performance minimal APIs with automatic OpenAPI documentation
  • Generic CRUD Operations: Reusable CRUD services with built-in validation and mapping
  • Entity Framework Core: Full ORM support with PostgreSQL provider
  • Soft Delete Support: Automatic soft deletion with audit trails
  • Pagination: Both offset-based and cursor-based pagination with comprehensive validation
  • Advanced Validation: FluentValidation with field existence validation, operator compatibility, and custom error responses
  • Dependency Injection: Built-in DI container with service registration
  • User Context: Built-in user-based authorization and auditing
  • Modern .NET: Leverages .NET 9 features including nullable types and records
  • Property Mapping: Dynamic field validation for ordering and filtering operations

📁 Project Structure

MasLazu.AspNet.Framework.sln
src/
├── MasLazu.AspNet.Framework.Domain/
│   └── Entities/
│       └── BaseEntity.cs
├── MasLazu.AspNet.Framework.Application/
│   ├── Interfaces/
│   │   ├── ICursorPaginationValidator.cs
│   │   ├── ICrudService.cs
│   │   ├── IEntityPropertyMap.cs
│   │   ├── IPaginationValidator.cs
│   │   ├── IRepository.cs
│   │   └── IReadRepository.cs
│   ├── Models/
│   │   ├── BaseDto.cs
│   │   ├── CursorPaginationRequest.cs
│   │   ├── CursorPaginatedResult.cs
│   │   ├── PaginationRequest.cs
│   │   └── PaginatedResult.cs
│   ├── Services/
│   │   └── CrudService.cs
│   ├── Validators/
│   │   ├── CursorPaginationRequestValidator.cs
│   │   ├── PaginationRequestValidator.cs
│   └── Utils/
├── MasLazu.AspNet.Framework.EfCore/
│   ├── Configurations/
│   ├── Data/
│   │   └── BaseDbContext.cs
│   ├── Extensions/
│   ├── Repositories/
│   │   ├── Repository.cs
│   │   └── ReadRepository.cs
│   └── Services/
├── MasLazu.AspNet.Framework.EfCore.Postgresql/
│   ├── Data/
│   └── Extensions/
└── MasLazu.AspNet.Framework.Endpoint/
    ├── EndpointGroups/
    │   ├── ApiEndpointGroup.cs
    │   └── V1EndpointGroup.cs
    ├── Endpoints/
    │   ├── BaseEndpoint.cs
    │   ├── BaseEndpointWithoutRequest.cs
    │   └── BaseEndpointWithoutResponse.cs
    ├── Extensions/
    ├── Middlewares/
    ├── Models/
    │   ├── SuccessResponse.cs
    │   └── ErrorResponse.cs
    └── Utils/

🏗️ Architecture

Domain Layer

  • Contains core business entities and domain logic
  • BaseEntity provides common properties: Id, CreatedAt, UpdatedAt, DeletedAt
  • No external dependencies

Application Layer

  • Business logic and use cases
  • Generic CrudService for common operations
  • DTOs and request/response models
  • Advanced validation with field existence checking and operator compatibility
  • Dual pagination support with comprehensive request validation
  • Property mapping for dynamic field validation and ordering

Infrastructure Layer

  • EF Core implementations
  • Repository pattern with read/write separation
  • Database contexts and configurations
  • External service integrations

Presentation Layer

  • FastEndpoints-based API endpoints
  • Standardized response models
  • Endpoint groups for versioning
  • Middleware and cross-cutting concerns

🔍 Advanced Features

Pagination & Validation

The framework provides comprehensive pagination and validation capabilities:

Offset-Based Pagination
// Request
{
  "page": 1,
  "pageSize": 20,
  "filters": [
    { "field": "name", "operator": "contains", "value": "test" }
  ],
  "orderBy": [
    { "field": "createdAt", "desc": true }
  ]
}

// Response
{
  "totalCount": 150,
  "pageSize": 20,
  "page": 1,
  "items": [...]
}
Cursor-Based Pagination
// Request
{
  "limit": 20,
  "cursor": "eyJpZCI6IjEyMyJ9", // Optional
  "filters": [
    { "field": "status", "operator": "=", "value": "active" }
  ],
  "orderBy": [
    { "field": "id", "desc": false }
  ]
}

// Response
{
  "items": [...],
  "nextCursor": "eyJpZCI6IjE0MyJ9"
}
Validation Features
  • Field Existence: Validates that filter/order fields exist and are available for operations
  • Operator Compatibility: Ensures operators are valid for field types
  • Type Safety: Validates data types match field types
  • Custom Error Messages: Clear, actionable error responses
Supported Operators by Type
  • String: =, !=, contains, startswith, endswith
  • Numeric/DateTime: =, !=, >, <, >=, <=
  • Boolean: =, !=
  • Enum/GUID: =, !=

📦 Dependencies

Core Dependencies

  • .NET 9.0
  • FastEndpoints - Minimal API framework
  • Entity Framework Core - ORM
  • Npgsql.EntityFrameworkCore.PostgreSQL - PostgreSQL provider
  • FluentValidation - Validation framework
  • Mapster - Object mapping
  • Microsoft.Extensions.DependencyInjection - DI container

Development Dependencies

  • EFCore.NamingConventions - Snake case naming
  • Microsoft.EntityFrameworkCore.Relational - Relational features
  • Microsoft.Extensions.Configuration - Configuration

🚀 Getting Started

Prerequisites

  • .NET 9.0 SDK
  • PostgreSQL database
  • Git

Installation

  1. Clone the repository:
git clone <repository-url>
cd MasLazu.AspNet.Framework
  1. Restore packages:
dotnet restore
  1. Configure your database connection in appsettings.json:
{
  "ConnectionStrings": {
    "DefaultConnection": "Host=localhost;Database=your_db;Username=your_user;Password=your_password"
  }
}
  1. Run database migrations:
dotnet ef database update
  1. Run the application:
dotnet run

💡 Usage Examples

Creating a New Entity

  1. Define your domain entity:
using MasLazu.AspNet.Framework.Domain.Entities;

public class Product : BaseEntity
{
    public string Name { get; set; } = string.Empty;
    public decimal Price { get; set; }
    public string Description { get; set; } = string.Empty;
}
  1. Create DTOs:
using MasLazu.AspNet.Framework.Application.Models;

public record ProductDto(Guid Id, DateTimeOffset CreatedAt, DateTimeOffset? UpdatedAt, string Name, decimal Price, string Description) : BaseDto(Id, CreatedAt, UpdatedAt);

public record CreateProductRequest(string Name, decimal Price, string Description);

public record UpdateProductRequest(Guid Id, string Name, decimal Price, string Description) : BaseUpdateRequest(Id);
  1. Implement the service:
using MasLazu.AspNet.Framework.Application.Services;

public class ProductService : CrudService<Product, ProductDto, CreateProductRequest, UpdateProductRequest>
{
    public ProductService(
        IRepository<Product> repository,
        IReadRepository<Product> readRepository,
        IUnitOfWork unitOfWork,
        IEntityPropertyMap<Product> propertyMap,
        IPaginationValidator<Product> paginationValidator,
        ICursorPaginationValidator<Product> cursorPaginationValidator,
        IValidator<CreateProductRequest>? createValidator = null,
        IValidator<UpdateProductRequest>? updateValidator = null)
        : base(repository, readRepository, unitOfWork, propertyMap, paginationValidator, cursorPaginationValidator, createValidator, updateValidator)
    {
    }

    // Use cursor pagination for large datasets
    public async Task<CursorPaginatedResult<ProductDto>> GetProductsCursorAsync(CursorPaginationRequest request)
    {
        return await GetCursorPaginatedAsync(Guid.Empty, request);
    }
}
  1. Create the endpoint:
using MasLazu.AspNet.Framework.Endpoint.Endpoints;
using MasLazu.AspNet.Framework.Endpoint.EndpointGroups;

public class GetProductsEndpoint : BaseEndpointWithoutRequest<List<ProductDto>>
{
    public override void ConfigureEndpoint()
    {
        Get("/products");
        Group<V1EndpointGroup>();
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        var service = Resolve<ProductService>();
        var products = await service.GetAllAsync(Guid.Empty, ct);
        await SendOkResponseAsync(products.ToList());
    }
}

Database Context Setup

using MasLazu.AspNet.Framework.EfCore.Data;
using Microsoft.EntityFrameworkCore;

public class AppDbContext : BaseDbContext
{
    public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }

    public DbSet<Product> Products { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        // Your entity configurations here
    }
}

🔧 Configuration

Dependency Injection Setup

using MasLazu.AspNet.Framework.Application.Interfaces;
using MasLazu.AspNet.Framework.Application.Extensions;
using MasLazu.AspNet.Framework.EfCore.Repositories;
using MasLazu.AspNet.Framework.EfCore.Data;

builder.Services.AddScoped(typeof(IRepository<>), typeof(Repository<,>));
builder.Services.AddScoped(typeof(IReadRepository<>), typeof(ReadRepository<,>));
builder.Services.AddScoped<IUnitOfWork, SharedTransactionUnitOfWork>();
builder.Services.AddScoped<AppDbContext>();

// Add framework validators
builder.Services.AddFrameworkApplicationValidators();

FastEndpoints Configuration

using FastEndpoints;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddFastEndpoints();

var app = builder.Build();
app.UseFastEndpoints();
app.Run();

📚 Key Concepts

Soft Deletes

All entities inherit from BaseEntity which includes a DeletedAt field. The framework automatically filters out soft-deleted records in queries.

User Context

All service methods include a userId parameter for authorization and auditing purposes.

Generic CRUD

The CrudService provides common CRUD operations that can be extended or overridden as needed.

Pagination

Supports both traditional offset-based pagination and modern cursor-based pagination:

  • Offset Pagination: Traditional page-based navigation with total count
  • Cursor Pagination: Token-based navigation for better performance with large datasets
  • Field Validation: Validates that sort and filter fields exist and are available for operations
  • Operator Validation: Ensures filter operators are compatible with field types
  • Type Safety: Runtime validation of field types and values

Validation

Integrated FluentValidation with advanced features:

  • Field Existence: Validates fields exist in the entity property map
  • Operator Compatibility: Checks operators against field types
  • Custom Error Messages: Clear, actionable validation errors
  • Automatic DI: Validators automatically registered via extension methods

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙋 Support

For questions and support, please open an issue on GitHub.


Built with ❤️ using .NET 9 and modern architectural patterns.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 (6)

Showing the top 5 NuGet packages that depend on MasLazu.AspNet.Framework.Endpoint:

Package Downloads
MasLazu.AspNet.Authentication.Password.Endpoint

Endpoint layer for MasLazu ASP.NET Password Authentication. Contains REST API endpoints using FastEndpoints framework.

MasLazu.AspNet.Authentication.Core.Endpoint

API endpoints for MasLazu ASP.NET Authentication Core. Contains REST API implementations using FastEndpoints.

MasLazu.AspNet.Verification.Endpoint

REST API endpoints for ASP.NET verification system using FastEndpoints.

MasLazu.AspNet.Authorization.Core.Endpoint

API endpoints layer for MasLazu.AspNet.Authorization.Core - contains FastEndpoints implementations for the authorization system.

MasLazu.AspNet.Authorization.Rbac.Endpoint

API endpoints for MasLazu ASP.NET Authorization RBAC. Contains FastEndpoints implementation for role and permission management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.9 22 9/23/2025
1.0.0-preview.8 42 9/22/2025
1.0.0-preview.6 233 9/19/2025
1.0.0-preview.5 275 9/17/2025
1.0.0-preview.1 247 9/17/2025