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.
✨ Features
| Feature | Description |
|---|---|
| 📝 Generic CRUD | Reusable operations for any entity type |
| ✅ Validation | Integrated FluentValidation support |
| 📄 Pagination | Built-in paging, sorting, and filtering |
| 🗑️ Soft Delete | Optional soft delete with automatic filtering |
| � Multi-Tenancy | Automatic tenant isolation with query filters |
| �🎣 Hooks | Extensible lifecycle hooks for customization |
| 🔄 CQRS Support | Optional CQRS pattern with MediatR |
| 🗺️ AutoMapper | Seamless DTO mapping integration |
| 🔐 Auth Integration | Automatic 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 GrydCrudbash
# 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.APIBasic 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/products - List with pagination
// GET /api/products/{id} - Get by ID
// POST /api/products - Create
// PUT /api/products/{id} - Update
// DELETE /api/products/{id} - Delete (soft or hard)
}📖 Documentation Sections
🚀
Getting Started
Complete setup guide from installation to first CRUD.
⚙️
Operations
Create, Read, Update, Delete operations in detail.
🎣
Hooks & Customization
Lifecycle hooks and extending default behavior.
✅
Validation
FluentValidation integration and custom validators.
🔄
CQRS Pattern
Commands, queries, and MediatR handlers.
📚
API Reference
Complete API documentation with examples.
🏗️ 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:
csharp
using Gryd.API.Attributes;
using GrydAuth.API.Attributes;
[ApiController]
[Route("api/[controller]")]
[AutoPermission("products")] // Generates permissions: create:products, read:products, etc.
public class ProductsController : CrudController<Product, ProductDto>
{
// GET /api/products - requires "read:products" permission
[HttpGet]
[RequirePermission("read:products")]
public override Task<IActionResult> GetAll([FromQuery] QueryParameters query)
=> base.GetAll(query);
// POST /api/products - requires "create:products" permission
[HttpPost]
[RequirePermission("create:products")]
public override Task<IActionResult> Create([FromBody] CreateProductDto dto)
=> base.Create(dto);
}Permission Generation
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", ...]
}
}🔗 Related Links
- Gryd.Core Documentation - Foundation utilities
- Gryd.Domain Documentation - DDD building blocks
- GrydAuth Module - Authentication and authorization