An Immediate.Validations adapter for MessageValidation — bridge source-generated, AOT-friendly, zero-reflection validators into the MessageValidation pipeline.
dotnet add package MessageValidation.ImmediateValidationsMark the message type with [Validate], make it partial, and implement IValidationTarget<T>. The Immediate.Validations source generator emits the Validate method at compile time.
using Immediate.Validations.Shared;
[Validate]
public partial record TemperatureReading : IValidationTarget<TemperatureReading>
{
[NotEmpty]
public required string SensorId { get; init; }
[GreaterThanOrEqualTo(-50)]
[LessThanOrEqualTo(150)]
public required double Value { get; init; }
}builder.Services.AddMessageValidation(options =>
{
options.MapSource<TemperatureReading>("sensors/+/temperature");
});
builder.Services.AddMessageImmediateValidations();That's it. The pipeline will call the source-generated TemperatureReading.Validate(...) static method for every incoming message — no reflection, no DI lookup per validation, AOT- and trim-friendly.
| Concern | DataAnnotations / FluentValidation | Immediate.Validations |
|---|---|---|
| Reflection at runtime | ✅ Yes | ❌ None |
| AOT / trim compatibility | ✅ Full | |
| Errors caught at compile time | ❌ No | ✅ Yes (analyzers + source gen) |
| Automatic NRT null checks | ❌ No | ✅ Yes |
- .NET 8.0+ (targets
net8.0andnet10.0) - MessageValidation >= 2.0.0
- Immediate.Validations >= 3.3.0