Skip to content

Source generated validations for Immediate.Handlers parameters

License

Notifications You must be signed in to change notification settings

tcortega/Immediate.Validations

 
 

Repository files navigation

Immediate.Validations

NuGet GitHub release GitHub license GitHub issues GitHub issues-closed GitHub Actions

Immediate.Validations is a source generator validating Immediate.Handlers handler parameters.

Installing Immediate.Validations

You can install Immediate.Validations with NuGet:

Install-Package Immediate.Validations

Or via the .NET Core command line interface:

dotnet add package Immediate.Validations

Either command, from Package Manager Console or .NET Core CLI, will download and install Immediate.Validations.

Using Immediate.Validations

Add Immediate.Validations to the Immediate.Handlers behaviors pipeline by including it in the list of default Behaviors for the assembly:

using Immediate.Validations.Shared;

[assembly: Behaviors(
	typeof(ValidationBehavior<,>)
)]

Creating Validation Classes

Indicate that a class should be validated by adding the [Validate] attribute and IValidationTarget<> interface:

[Validate]
public record Query : IValidationTarget<Query>;

When Nullable Reference Types is enabled, any non-nullable reference types are automatically checked for null. Other validations are available like so:

[Validate]
public record Query : IValidationTarget<Query>
{
	[GreaterThan(0)]
	public required int Id { get; init; }
}

Results

The result of doing the above is that when a parameter fails one or more validations, a ValidationException is thrown, which can be handled via ProblemDetails or any other infrastructure mechanism.

About

Source generated validations for Immediate.Handlers parameters

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%