Skip to content

DI Extensions

Extensões do Gryd.API para DI e pipeline HTTP.

ServiceCollectionExtensions

AddGrydCore(...)

Registra:

  • MediatR
  • FluentValidation
  • ValidationBehavior
  • IDateTimeService
csharp
builder.Services.AddGrydCore(typeof(Program).Assembly);

AddCoreExceptionHandler()

Registra o fallback de exceções usando IExceptionHandler:

csharp
builder.Services.AddCoreExceptionHandler();

ApplicationBuilderExtensions

UseCorrelationId()

Adiciona correlação de request/response (X-Correlation-ID, X-Request-ID).

UseGryd(app.Environment)

Mantido para conveniência; hoje aplica:

  • UseCorrelationId()
  • UseExceptionHandler() (pipeline unificado .NET 8+)

Exemplo completo

csharp
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddGrydCore(typeof(Program).Assembly);
builder.Services.AddCoreExceptionHandler();

var app = builder.Build();

app.UseExceptionHandler();
app.UseCorrelationId();

app.MapControllers();
app.Run();

Released under the MIT License.