DI Extensions
Extension methods for service registration.
ServiceCollectionExtensions
AddGrydCore
Registers MediatR, FluentValidation, and core services.
csharp
// With assemblies
services.AddGrydCore(typeof(Program).Assembly, typeof(CreateUserCommand).Assembly);// Single assembly services.AddGrydCore(typeof(Program).Assembly);
// Calling assembly services.AddGrydCore();
What It Registers
- MediatR handlers from assemblies
- ValidationBehavior pipeline
- FluentValidation validators
- SystemDateTimeService as IDateTimeService
ApplicationBuilderExtensions
UseExceptionHandling
csharp
app.UseExceptionHandling(includeStackTrace: false);// Or based on environment app.UseExceptionHandling(app.Environment);
UseCorrelationId
csharp
app.UseCorrelationId();UseGryd
Combines correlation ID and exception handling.
csharp
app.UseGryd(app.Environment);Full Example
csharp
var builder = WebApplication.CreateBuilder(args);builder.Services.AddControllers(); builder.Services.AddGrydCore(typeof(Program).Assembly);
var app = builder.Build();
app.UseGryd(app.Environment); app.MapControllers(); app.Run();