CLI Templates
Gryd.IO provides CLI templates for dotnet new to quickly scaffold new projects with the correct structure and dependencies.
Installation
Install all Gryd.IO templates from NuGet:
dotnet new install Gryd.IO.TemplatesOr install from a local folder (for development):
dotnet new install ./templates/gryd-api
dotnet new install ./templates/gryd-minimal
dotnet new install ./templates/gryd-moduleAvailable Templates
| Template | Short Name | Description |
|---|---|---|
| Gryd API | gryd-api | Complete API with Auth + Crud modules |
| Gryd Minimal | gryd-minimal | Minimal API with Core packages only |
| Gryd Module | gryd-module | Clean Architecture module structure |
gryd-api
Complete API template with optional GrydAuth and GrydCrud integration, Docker support, and database configuration.
Usage
# Create with defaults (Auth + Crud + PostgreSQL + Docker)
dotnet new gryd-api -n MyApiProject
# Create without authentication
dotnet new gryd-api -n MyApiProject --IncludeAuth false
# Create with SQL Server instead of PostgreSQL
dotnet new gryd-api -n MyApiProject --UsePostgres false --UseSqlServer true
# Create without Docker support
dotnet new gryd-api -n MyApiProject --IncludeDocker falseParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
--IncludeAuth | bool | true | Include GrydAuth for authentication/authorization |
--IncludeCrud | bool | true | Include GrydCrud for CRUD operations |
--UsePostgres | bool | true | Configure PostgreSQL as database |
--UseSqlServer | bool | false | Configure SQL Server as database |
--IncludeDocker | bool | true | Include Dockerfile and docker-compose.yml |
Generated Structure
MyApiProject/
├── MyApiProject.csproj # Project with Gryd packages
├── Program.cs # Startup with DI configuration
├── appsettings.json # Production configuration
├── appsettings.Development.json # Development configuration
├── README.md # Project documentation
├── Controllers/
│ └── ProductsController.cs # Example CRUD controller
├── Data/
│ └── AppDbContext.cs # EF Core DbContext
├── Domain/
│ └── Product.cs # Example entity
├── DTOs/
│ └── ProductDtos.cs # DTOs for Product entity
├── Dockerfile # (if IncludeDocker=true)
├── docker-compose.yml # (if IncludeDocker=true)
└── .dockerignore # (if IncludeDocker=true)Program.cs Example
var builder = WebApplication.CreateBuilder(args);
// Add Gryd Core
builder.Services.AddGrydCore();
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
// Add GrydAuth (if IncludeAuth=true)
builder.Services.AddGrydAuth(builder.Configuration);
// Add GrydCrud (if IncludeCrud=true)
builder.Services.AddGrydCrud();
builder.Services.AddCrudFor<Product, ProductDto, CreateProductDto, UpdateProductDto>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthentication(); // if IncludeAuth=true
app.UseGrydAuth(); // if IncludeAuth=true
app.UseAuthorization();
app.MapControllers();
app.Run();gryd-minimal
Minimal API template with only Gryd.Core packages. Perfect for microservices or simple APIs that don't need full CRUD or authentication features.
Usage
# Create with defaults (PostgreSQL)
dotnet new gryd-minimal -n MyMinimalApi
# Create with SQL Server
dotnet new gryd-minimal -n MyMinimalApi --UsePostgres false --UseSqlServer trueParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
--UsePostgres | bool | true | Configure PostgreSQL as database |
--UseSqlServer | bool | false | Configure SQL Server as database |
Generated Structure
MyMinimalApi/
├── MyMinimalApi.csproj # Project with Gryd.Core packages
├── Program.cs # Minimal startup configuration
├── appsettings.json # Production configuration
├── appsettings.Development.json # Development configuration
├── README.md # Project documentation
├── Controllers/
│ └── HelloController.cs # Example controller
└── Data/
└── AppDbContext.cs # EF Core DbContextProgram.cs Example
var builder = WebApplication.CreateBuilder(args);
// Add Gryd Core
builder.Services.AddGrydCore();
// Add Database
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();gryd-module
Clean Architecture module template. Creates a complete module structure following Domain-Driven Design principles, ready to be integrated into a host application.
Usage
# Create with defaults (ModuleName=MyModule, with Tests and API)
dotnet new gryd-module -n Catalog
# Create with custom module name
dotnet new gryd-module -n Catalog --ModuleName Products
# Create without tests
dotnet new gryd-module -n Catalog --IncludeTests false
# Create without API layer (library only)
dotnet new gryd-module -n Catalog --IncludeApi falseParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
--ModuleName | string | MyModule | Name of the module (used in namespaces) |
--IncludeTests | bool | true | Include test project with xUnit |
--IncludeApi | bool | true | Include API layer with controllers |
Generated Structure
Catalog/
├── Catalog.sln # Solution file
├── README.md # Module documentation
│
├── src/
│ ├── Catalog.Domain/ # Domain Layer
│ │ ├── Catalog.Domain.csproj
│ │ ├── GlobalUsings.cs
│ │ ├── CatalogDomainAssemblyMarker.cs
│ │ └── Entities/
│ │ └── SampleEntity.cs # Example aggregate root
│ │
│ ├── Catalog.Application/ # Application Layer
│ │ ├── Catalog.Application.csproj
│ │ ├── GlobalUsings.cs
│ │ ├── CatalogApplicationAssemblyMarker.cs
│ │ ├── DTOs/
│ │ │ └── SampleEntityDtos.cs # DTOs for CRUD operations
│ │ └── Features/
│ │ └── SampleEntities/
│ │ ├── Commands/
│ │ │ └── SampleEntityCommands.cs # Create, Update, Delete
│ │ ├── Queries/
│ │ │ └── SampleEntityQueries.cs # GetById, GetPaged
│ │ └── Validators/
│ │ └── SampleEntityValidators.cs
│ │
│ ├── Catalog.Infrastructure/ # Infrastructure Layer
│ │ ├── Catalog.Infrastructure.csproj
│ │ ├── GlobalUsings.cs
│ │ ├── CatalogInfrastructureAssemblyMarker.cs
│ │ └── CatalogServiceCollectionExtensions.cs
│ │
│ └── Catalog.API/ # API Layer (if IncludeApi=true)
│ ├── Catalog.API.csproj
│ ├── GlobalUsings.cs
│ ├── CatalogApiServiceCollectionExtensions.cs
│ └── Controllers/
│ └── SampleEntitiesController.cs
│
└── tests/ # (if IncludeTests=true)
└── Catalog.Tests/
├── Catalog.Tests.csproj
├── GlobalUsings.cs
└── Domain/
└── SampleEntityTests.cs # Unit tests for domainLayer Details
Domain Layer
Contains entities, value objects, and domain events. No external dependencies.
// Entities/SampleEntity.cs
public class SampleEntity : AggregateRoot
{
public string Name { get; private set; } = string.Empty;
public string? Description { get; private set; }
public bool IsActive { get; private set; } = true;
public static SampleEntity Create(string name, string? description = null)
{
Guard.NotNullOrWhiteSpace(name, nameof(name));
var entity = new SampleEntity
{
Id = Guid.NewGuid(),
Name = name,
Description = description,
IsActive = true
};
return entity;
}
public void Update(string name, string? description)
{
Guard.NotNullOrWhiteSpace(name, nameof(name));
Name = name;
Description = description;
}
public void Activate() => IsActive = true;
public void Deactivate() => IsActive = false;
}Application Layer
Contains DTOs, CQRS commands/queries, and validators.
// Features/SampleEntities/Commands/SampleEntityCommands.cs
public record CreateSampleEntityCommand(string Name, string? Description)
: ICommand<Result<SampleEntityDto>>;
public record UpdateSampleEntityCommand(Guid Id, string Name, string? Description)
: ICommand<Result<SampleEntityDto>>;
public record DeleteSampleEntityCommand(Guid Id)
: ICommand<Result>;Infrastructure Layer
Contains service registration and external integrations.
// CatalogServiceCollectionExtensions.cs
public static class CatalogServiceCollectionExtensions
{
public static IServiceCollection AddCatalog(this IServiceCollection services, IConfiguration configuration)
{
services.AddCatalogApplication();
services.AddCatalogInfrastructure(configuration);
return services;
}
}API Layer
Contains controllers that use MediatR to dispatch commands/queries.
// Controllers/SampleEntitiesController.cs
[ApiController]
[Route("api/[controller]")]
public class SampleEntitiesController : BaseController
{
private readonly ISender _sender;
[HttpGet]
public async Task<IActionResult> GetAll([FromQuery] int page = 1, [FromQuery] int pageSize = 10)
{
var query = new GetSampleEntitiesQuery(page, pageSize);
var result = await _sender.Send(query);
return FromResult(result);
}
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateSampleEntityDto dto)
{
var command = new CreateSampleEntityCommand(dto.Name, dto.Description);
var result = await _sender.Send(command);
return FromResult(result);
}
}Integration with Host Application
- Add project references to your host:
<ProjectReference Include="path/to/Catalog.API/Catalog.API.csproj" />
<ProjectReference Include="path/to/Catalog.Infrastructure/Catalog.Infrastructure.csproj" />- Register services in Program.cs:
// Add the module
builder.Services.AddCatalog(builder.Configuration);
// Add controllers from the module
builder.Services.AddControllers()
.AddCatalogControllers();- Configure the database context to include module entities:
public class AppDbContext : DbContext
{
public DbSet<SampleEntity> SampleEntities => Set<SampleEntity>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfigurationsFromAssembly(
typeof(CatalogInfrastructureAssemblyMarker).Assembly);
}
}Uninstalling Templates
To remove installed templates:
dotnet new uninstall Gryd.IO.TemplatesOr for locally installed:
dotnet new uninstall ./templates/gryd-api
dotnet new uninstall ./templates/gryd-minimal
dotnet new uninstall ./templates/gryd-moduleList Installed Templates
dotnet new list grydOutput:
Template Name Short Name Language Tags
-------------- ----------- -------- ----
Gryd API gryd-api [C#] Web/API/Gryd
Gryd Minimal gryd-minimal [C#] Web/API/Gryd
Gryd Module gryd-module [C#] Library/Gryd/Module