Skip to content

GrydCrud Module

GrydCrud is a powerful CRUD operations framework for .NET applications. It provides generic, reusable components for Create, Read, Update, and Delete operations with built-in validation, pagination, soft delete, and hooks for customization.

HTTP Contract V1 (important)
Success responses now return payload directly (no Result<T> envelope in HTTP body).
Errors are standardized with ProblemDetails.
Frontend de/para guide: /frontend/v1-http-contract-migration.

✨ Features

FeatureDescription
📝 Generic CRUDReusable operations for any entity type
ValidationIntegrated FluentValidation support
📄 PaginationBuilt-in paging, sorting, and filtering
🗑️ Soft DeleteOptional soft delete with automatic filtering
Multi-TenancyAutomatic tenant isolation with query filters
�🎣 HooksExtensible lifecycle hooks for customization
🔄 CQRS SupportOptional CQRS pattern with MediatR
🗺️ AutoMapperSeamless DTO mapping integration
🔐 Auth IntegrationAutomatic permission generation with GrydAuth

📦 Packages

GrydCrud is modular - use only what you need:

📦 GrydCrud
├── GrydCrud.Core           # Core interfaces and operations
├── GrydCrud.Services       # Service layer abstractions
├── GrydCrud.Cqrs           # CQRS commands, queries, handlers
├── GrydCrud.API            # Controllers and endpoints
├── GrydCrud.AutoMapper     # AutoMapper integration
├── GrydCrud.FluentValidation # FluentValidation integration
├── GrydCrud.Auth           # GrydAuth permission integration
└── GrydCrud (meta-package) # All packages combined

🚀 Quick Start

Installation

bash
# Install everything
dotnet add package GrydCrud
bash
# Core only
dotnet add package GrydCrud.Core

# With services
dotnet add package GrydCrud.Services

# With CQRS
dotnet add package GrydCrud.Cqrs

# With API controllers
dotnet add package GrydCrud.API

Basic Setup

csharp
// Program.cs
using GrydCrud.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add GrydCrud with all features
builder.Services.AddGrydCrud(options =>
{
    options.UseSoftDelete = true;
    options.EnableValidation = true;
    options.DefaultPageSize = 20;
    options.MaxPageSize = 100;
});

// Register CRUD for your entities
builder.Services.AddCrudFor<Product, ProductDto>();
builder.Services.AddCrudFor<Category, CategoryDto>();

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

Create Your First CRUD Entity

csharp
// Domain/Entities/Product.cs
using Gryd.Domain.Primitives;
using Gryd.Domain.Abstractions;

public class Product : AggregateRoot
{
    public string Name { get; set; } = string.Empty;
    public string Description { get; set; } = string.Empty;
    public decimal Price { get; set; }
    public int Stock { get; set; }
    public Guid CategoryId { get; set; }
}
csharp
// Application/DTOs/ProductDto.cs
public record ProductDto(
    Guid Id,
    string Name,
    string Description,
    decimal Price,
    int Stock,
    Guid CategoryId
);

public record CreateProductDto(
    string Name,
    string Description,
    decimal Price,
    int Stock,
    Guid CategoryId
);

public record UpdateProductDto(
    string Name,
    string Description,
    decimal Price,
    int Stock
);

Create a CRUD Controller

csharp
// API/Controllers/ProductsController.cs
using GrydCrud.API.Controllers;
using GrydCrud.Services.Abstractions;
using GrydCrud.Core.Models;

[Route("api/[controller]")]
public class ProductsController : CrudController<Product, CreateProductDto, UpdateProductDto, ProductDto, QueryParameters>
{
    public ProductsController(
        ICrudService<Product, CreateProductDto, UpdateProductDto, ProductDto, QueryParameters> crudService)
        : base(crudService)
    {
    }
    
    // That's it! You get all CRUD endpoints automatically:
    // GET    /api/v1/products          - List with pagination
    // GET    /api/v1/products/{id}     - Get by ID
    // POST   /api/v1/products          - Create
    // PUT    /api/v1/products/{id}     - Update
    // DELETE /api/v1/products/{id}     - Delete (soft or hard)
}

📖 Documentation Sections

🏗️ Architecture Overview

┌─────────────────────────────────────────────────────────────────┐
│                       GrydCrud.API                              │
│  ┌─────────────────────────────────────────────────────────────┐│
│  │ CrudController<TEntity, TDto>                               ││
│  │ CqrsCrudController<TEntity, TDto>                           ││
│  └─────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────┘

              ┌───────────────┴───────────────┐
              ▼                               ▼
┌─────────────────────────┐     ┌─────────────────────────────────┐
│    GrydCrud.Services    │     │         GrydCrud.Cqrs           │
│  ┌───────────────────┐  │     │  ┌───────────────────────────┐  │
│  │   ICrudService    │  │     │  │ CreateEntityCommand       │  │
│  │   CrudService     │  │     │  │ UpdateEntityCommand       │  │
│  └───────────────────┘  │     │  │ DeleteEntityCommand       │  │
└─────────────────────────┘     │  │ GetEntityByIdQuery        │  │
              │                 │  │ GetEntitiesPagedQuery     │  │
              │                 │  └───────────────────────────┘  │
              │                 └─────────────────────────────────┘
              │                               │
              └───────────────┬───────────────┘

┌─────────────────────────────────────────────────────────────────┐
│                       GrydCrud.Core                             │
│  ┌─────────────────────────────────────────────────────────────┐│
│  │ Operations:                                                  ││
│  │  - ICreateOperation<TEntity, TCreateDto, TResultDto>        ││
│  │  - IUpdateOperation<TEntity, TUpdateDto, TResultDto>        ││
│  │  - IDeleteOperation<TEntity>                                ││
│  │  - IGetByIdOperation<TEntity, TResultDto>                   ││
│  │  - IQueryOperation<TEntity, TResultDto, TQueryParams>       ││
│  └─────────────────────────────────────────────────────────────┘│
│  ┌─────────────────────────────────────────────────────────────┐│
│  │ Models: QueryParameters, CrudOptions, PagedResult           ││
│  └─────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│              Gryd.Infrastructure (Repository, UoW)              │
└─────────────────────────────────────────────────────────────────┘

🔐 GrydAuth Integration

GrydCrud integrates seamlessly with GrydAuth for automatic permission-based authorization. With GrydCrud.Auth, controllers that use [AutoPermission] get CRUD permissions enforced automatically — no method overrides needed.

Setup

csharp
// Program.cs
builder.Services.AddGrydCrudAuth(autoPermissions: true);

Zero-Boilerplate Controller

csharp
using Gryd.API.Attributes;

[AutoPermission("products")]
[Route("api/[controller]")]
public class ProductsController : CrudController<Product, CreateProductDto, UpdateProductDto, ProductDto, QueryParameters>
{
    public ProductsController(ICrudService<...> service) : base(service) { }

    // ✅ All CRUD endpoints are protected automatically:
    // GET    /api/v1/products       → read:products
    // GET    /api/v1/products/{id}  → read:products
    // POST   /api/v1/products       → create:products
    // PUT    /api/v1/products/{id}  → update:products
    // DELETE /api/v1/products/{id}  → delete:products
}

The CrudPermissionConvention applies AuthorizeFilter at startup, leveraging the existing PermissionPolicyProvider and PermissionAuthorizationHandler from GrydAuth.

Permission Generation for Seeding

csharp
using GrydCrud.Auth.Abstractions;

public class PermissionSeeder
{
    private readonly ICrudPermissionGenerator _generator;
    
    public List<string> GetAllPermissions()
    {
        return _generator.GeneratePermissions(
            typeof(ProductsController).Assembly
        );
        // Returns: ["create:products", "read:products", "update:products", "delete:products", ...]
    }
}

Full Documentation

See the Permissions & Authorization page for complete documentation including customization, exclusions, and architecture details.

Released under the MIT License.