Appearance
Getting Started
This guide walks you through setting up GrydReports in your .NET application, from installation to generating your first report.
Prerequisites
- .NET 10.0 or later
- PostgreSQL (for execution history persistence)
- An existing Gryd.IO project (or use the gryd-api template)
- GrydFiles and an object-storage provider; see Files getting started
1. Installation
Install the Reports stack and at least one renderer. The meta-package does not include renderer packages:
bash
dotnet add package GrydReports
dotnet add package GrydReports.Infrastructure.QuestPdfIf you also need recurring scheduling with GrydJobs, add:
bash
dotnet add package GrydReports.Scheduling.GrydJobs
dotnet add package GrydJobsInstall the PDF renderer for the examples below. Add the Excel or CSV renderer package and registration only when those formats are required:
bash
# PDF reports with QuestPDF
dotnet add package GrydReports.Infrastructure.QuestPdf
# Excel reports with ClosedXML
dotnet add package GrydReports.Infrastructure.ClosedXml
# CSV reports with CsvHelper
dotnet add package GrydReports.Infrastructure.CsvHelper2. Configure Services
Use the generated API template for the complete host pipeline, including API versioning, Files, object storage, and middleware. Its maintained Program.cs shows the full composition. In the host's service-registration section, add GrydFiles, one renderer, and Reports:
csharp
using Gryd.Infrastructure.Extensions;
using GrydFiles;
using GrydFiles.Infrastructure.ClamAv;
using GrydReports;
using GrydReports.Core.Configuration;
using GrydReports.Infrastructure.QuestPdf;
using Microsoft.EntityFrameworkCore;
builder.Services.AddGrydObjectStorage(builder.Configuration);
builder.Services.AddGrydFiles(builder.Configuration);
builder.Services.AddGrydFilesClamAv(builder.Configuration);
builder.Services.AddGrydReportsQuestPdf();
builder.Services.AddGrydReports(
builder.Configuration,
db => db.UseNpgsql(builder.Configuration.GetConnectionString("GrydReports")));
builder.Services.Configure<GrydReportsOptions>(options =>
options.TemplateAssemblies.Add(typeof(Program).Assembly));This example installs the QuestPDF renderer package. Add and register the ClosedXML or CsvHelper renderer packages only when the host needs those formats. Template discovery scans only assemblies listed in TemplateAssemblies; setting AutoRegisterTemplates by itself does not discover the host assembly from configuration. The template and data-source implementations below are application-owned and must also be registered with DI as shown later in this guide.
3. Add Configuration
Add the following to your appsettings.json. The gryd.report profile is required — the module refuses to start without it (see Configuration).
json
{
"ConnectionStrings": {
"GrydReports": "Host=localhost;Database=gryd_reports;Username=postgres;Password=postgres"
},
"GrydReports": {
"AutoRegisterTemplates": true
},
"GrydFiles": {
"Profiles": {
"gryd.report": {
"MaxSizeBytes": 52428800,
"AllowedContentTypes": ["application/pdf", "text/csv",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],
"ScanRequired": false,
"DefaultRetentionMode": "UntilReleased"
}
}
},
"GrydStorage": {
"DefaultProvider": "AmazonS3",
"AmazonS3": {
"BucketName": "company-reports",
"Region": "us-east-1",
"AccessKeyId": "",
"SecretAccessKey": "",
"DefaultPrefix": "reports"
}
}
}4. Define a Data Model
Create a class that represents your report data:
csharp
// Reports/Models/InvoiceData.cs
public class InvoiceData
{
public string CompanyName { get; set; } = default!;
public string CustomerName { get; set; } = default!;
public string InvoiceNumber { get; set; } = default!;
public DateTime IssueDate { get; set; }
public DateTime DueDate { get; set; }
public List<InvoiceLineItem> Items { get; set; } = [];
public decimal Subtotal => Items.Sum(i => i.Total);
public decimal Tax => Subtotal * 0.1m;
public decimal GrandTotal => Subtotal + Tax;
}
public class InvoiceLineItem
{
public string Description { get; set; } = default!;
public int Quantity { get; set; }
public decimal UnitPrice { get; set; }
public decimal Total => Quantity * UnitPrice;
}5. Implement a Data Source
The data source fetches data from your business layer:
csharp
// Reports/DataSources/InvoiceDataSource.cs
using GrydReports.Core.Abstractions;
public class InvoiceDataSource : IReportDataSource<InvoiceData, InvoiceParameters>
{
private readonly IInvoiceRepository _invoices;
public InvoiceDataSource(IInvoiceRepository invoices) => _invoices = invoices;
public async Task<InvoiceData> FetchDataAsync(
InvoiceParameters parameters, CancellationToken ct)
{
var invoice = await _invoices.GetByNumberAsync(parameters.InvoiceNumber, ct)
?? throw new InvalidOperationException($"Invoice {parameters.InvoiceNumber} not found");
return new InvoiceData
{
CompanyName = "Acme Corp",
CustomerName = invoice.CustomerName,
InvoiceNumber = invoice.Number,
IssueDate = invoice.IssueDate,
DueDate = invoice.DueDate,
Items = invoice.Lines.Select(l => new InvoiceLineItem
{
Description = l.Description,
Quantity = l.Quantity,
UnitPrice = l.UnitPrice
}).ToList()
};
}
}
// Reports/Models/InvoiceParameters.cs
public class InvoiceParameters
{
public string InvoiceNumber { get; set; } = default!;
}6. Create a Report Template
The template defines metadata and structure:
csharp
// Reports/Templates/InvoiceTemplate.cs
using GrydReports.Core.Abstractions;
using GrydReports.Core.Enums;
using GrydReports.Core.Models;
public class InvoiceTemplate : IReportTemplate<InvoiceData>
{
public string TemplateId => "invoice";
public string DisplayName => "Invoice Report";
public string? Description => "Generates printable invoices";
public IReadOnlyList<ReportFormat> SupportedFormats =>
[ReportFormat.Pdf];
public IReadOnlyList<ReportParameterDefinition> Parameters =>
[
new("invoiceNumber", "Invoice Number", "string", required: true)
];
public ReportMetadata GetMetadata(InvoiceData data) => new()
{
Title = $"Invoice #{data.InvoiceNumber}",
Author = data.CompanyName,
Subject = $"Invoice for {data.CustomerName}"
};
}7. Register Dependencies
Register your custom types in DI:
csharp
// Program.cs (after AddGrydReports)
builder.Services.AddScoped<IReportDataSource<InvoiceData, InvoiceParameters>, InvoiceDataSource>();
builder.Services.AddSingleton<IReportTemplate<InvoiceData>, InvoiceTemplate>();8. Generate a Report
Via API
bash
# Synchronous generation
curl -X POST http://localhost:5000/api/v1/reports/generate \
-H "Content-Type: application/json" \
-d '{
"templateId": "invoice",
"format": 1,
"parameters": { "invoiceNumber": "INV-2026-001" }
}'
# Response: 201 Created
# {
# "id": "a1b2c3d4-...",
# "templateId": "invoice",
# "status": 3,
# "fileName": "invoice-2026-001.pdf",
# "storedFileId": "0b8e2f51-..."
# }
# Then ask for a short-lived URL and fetch the file from it:
curl http://localhost:5000/api/v1/reports/a1b2c3d4-.../download
# { "url": "https://storage.../invoice-2026-001.pdf?X-Amz-Signature=...", "expiresAt": "..." }Via Code (MediatR)
csharp
var result = await mediator.Send(new GenerateReportCommand(
TemplateId: "invoice",
Format: ReportFormat.Pdf,
Parameters: new Dictionary<string, object?> { ["invoiceNumber"] = "INV-2026-001" }
));
if (result.IsSuccess)
{
Console.WriteLine($"Report generated: {result.Data!.FileName}");
Console.WriteLine($"Download URL from: /api/v1/reports/{result.Data.Id}/download");
}Next Steps
- Configuration — Fine-tune supported options and permissions
- Templates — Advanced template patterns (PDF layouts, Excel sheets)
- Generation — Synchronous generation and one-shot async limitations
- Scheduling — Set up recurring reports with cron expressions
- Delivery — Configure delivery and host email transport
- Migration (No Jobs) — Remove GrydJobs when scheduling is not needed