Getting Started
Welcome to Gryd.IO! This guide will help you get up and running quickly.
Quick Start with Templates
The fastest way to start a new project is using our CLI templates:
bash
# Install Gryd.IO templates
dotnet new install Gryd.IO.Templates
# Create a complete API with Auth + Crud
dotnet new gryd-api -n MyApiProject
# Or create a minimal API
dotnet new gryd-minimal -n MyMinimalApi
# Or create a new module for an existing project
dotnet new gryd-module -n Catalog --ModuleName ProductsTIP
See the CLI Templates documentation for all available options and generated structures.
Prerequisites
- .NET 9.0 SDK or later
- Your favorite IDE (Visual Studio, VS Code, Rider)
- Basic knowledge of C# and ASP.NET Core
Manual Installation
Using NuGet
Install the packages you need via NuGet:
bash
# Install all core packages
dotnet add package Gryd.Core
dotnet add package Gryd.Domain
dotnet add package Gryd.Application
dotnet add package Gryd.Infrastructure
dotnet add package Gryd.APIbash
Install-Package Gryd.Core
Install-Package Gryd.Domain
Install-Package Gryd.Application
Install-Package Gryd.Infrastructure
Install-Package Gryd.APIxml
<<ItemGroup>
<PackageReference Include="Gryd.Core" Version="1.0.*" />
<PackageReference Include="Gryd.Domain" Version="1.0.*" />
<PackageReference Include="Gryd.Application" Version="1.0.*" />
<PackageReference Include="Gryd.Infrastructure" Version="1.0.*" />
<PackageReference Include="Gryd.API" Version="1.0.*" />
</ItemGroup>Project Structure
Gryd.IO follows Clean Architecture principles. Here's the recommended structure:
📦 YourApplication/
├── 📁 src/
│ ├── 📁 Core/
│ │ ├── 📁 YourApp.Domain/ # Entities, ValueObjects, Events
│ │ └── 📁 YourApp.Application/ # Commands, Queries, Handlers
│ ├── 📁 Infrastructure/
│ │ └── 📁 YourApp.Infrastructure/ # Repositories, External Services
│ └── 📁 Presentation/
│ └── 📁 YourApp.API/ # Controllers, Middlewares
└── 📁 tests/
├── 📁 YourApp.Domain.Tests/
├── 📁 YourApp.Application.Tests/
└── 📁 YourApp.API.Tests/Quick Example
Let's create a simple entity and use the framework:
1. Create a Domain Entity
csharp
using Gryd.Domain.Base;
using Gryd.Domain.Events;
namespace YourApp.Domain.Entities;
public class Product : AggregateRoot<<Guid>
{
public string Name { get; private set; } = string.Empty;
public string Description { get; private set; } = string.Empty;
public decimal Price { get; private set; }
public bool IsActive { get; private set; } = true;
protected Product() { } // EF Core constructor
public static Product Create(string name, string description, decimal price)
{
var product = new Product
{
Id = Guid.NewGuid(),
Name = name,
Description = description,
Price = price
};
product.AddDomainEvent(new ProductCreatedEvent(product.Id, name));
return product;
}
public void UpdatePrice(decimal newPrice)
{
Guard.Against.NegativeOrZero(newPrice, nameof(newPrice));
Price = newPrice;
SetUpdatedAt();
}
public void Deactivate()
{
IsActive = false;
SetUpdatedAt();
}
}
// Domain Event
public record ProductCreatedEvent(Guid ProductId, string Name) : DomainEvent;2. Create a Command
csharp
using Gryd.Application.Abstractions.Messaging;
using Gryd.Application.Common;
namespace YourApp.Application.Products.Commands;
// Command
public record CreateProductCommand(
string Name,
string Description,
decimal Price
) : ICommand<<Guid>;
// Validator
public class CreateProductCommandValidator
: AbstractValidator<<CreateProductCommand>
{
public CreateProductCommandValidator()
{
RuleFor(x => x.Name)
.NotEmpty()
.MaximumLength(200);
RuleFor(x => x.Description)
.MaximumLength(1000);
RuleFor(x => x.Price)
.GreaterThan(0);
}
}
// Handler
public class CreateProductCommandHandler
: ICommandHandler<CreateProductCommand, Guid>
{
private readonly IProductRepository _repository;
private readonly IUnitOfWork _unitOfWork;
public CreateProductCommandHandler(
IProductRepository repository,
IUnitOfWork unitOfWork)
{
_repository = repository;
_unitOfWork = unitOfWork;
}
public async Task<Result<<Guid>> Handle(
CreateProductCommand request,
CancellationToken cancellationToken)
{
var product = Product.Create(
request.Name,
request.Description,
request.Price
);
await _repository.AddAsync(product, cancellationToken);
await _unitOfWork.CommitAsync(cancellationToken);
return Result<<Guid>.Success(product.Id);
}
}3. Create an API Controller
csharp
using Gryd.API.Controllers;
using MediatR;
using Microsoft.AspNetCore.Mvc;
namespace YourApp.API.Controllers;
[Route("api/[controller]")]
public class ProductsController : GrydBaseController
{
public ProductsController(IMediator mediator) : base(mediator)
{
}
[HttpPost]
public async Task<<IActionResult> Create(
[FromBody] CreateProductCommand command,
CancellationToken cancellationToken)
{
var result = await Mediator.Send(command, cancellationToken);
return HandleResult(result, id => CreatedAtAction(
nameof(GetById),
new { id },
new { id }
));
}
[HttpGet("{id:guid}")]
public async Task<<IActionResult> GetById(
Guid id,
CancellationToken cancellationToken)
{
var query = new GetProductByIdQuery(id);
var result = await Mediator.Send(query, cancellationToken);
return HandleResult(result);
}
}4. Configure Services
csharp
using Gryd.API.Extensions;
using Gryd.Application.Extensions;
using Gryd.Infrastructure.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add Gryd.IO services
builder.Services
.AddGrydApplication(typeof(CreateProductCommand).Assembly)
.AddGrydInfrastructure(builder.Configuration)
.AddGrydApi();
// Add your own services
builder.Services.AddScoped<IProductRepository, ProductRepository>();
var app = builder.Build();
// Use Gryd.IO middleware
app.UseGryd();
app.MapControllers();
app.Run();What's Next?
Now that you have the basics, explore each package in detail:
🧰
Gryd.Core
Extensions and Guard clauses
🏛️
Gryd.Domain
DDD building blocks
⚙️
Gryd.Application
CQRS and Result patterns
🔌
Gryd.Infrastructure
Repository and abstractions
🌐
Gryd.API
Controllers and middlewares
Need Help?
- 📖 Check the API Reference
- 💬 Join our Discord Community
- 🐛 Report issues on GitHub