csharpfritz / csharpfritz/InstantAPIs

Validation layer

Open
#61 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
453
Forks
58
PR merge metrics
No merged PRs in 30d

Description

It would be nice if this whole process could be like a pluggable pipeline (kind of like middleware) where I can just slot in additional functionality. So initial example would just be to add a fluent validator based on each db model and use attributes like [Required] or [MaxLength(500)] to hint to the validation rules that will apply for that object.

```c#
public class MyClass
{
[Required]
public string Name { get; set; }
[MaxLength(500)]
public string Description { get; set; }
}

public class MyClassValidator : AbstractValidator
{
public MyClassValidator()
{
RuleFor(request => request.Name)
.Must(x => !string.IsNullOrWhiteSpace(x))
.WithMessage(x => "Name is required!");
RuleFor(request => request.Description)
.MaximumLength(500)
.WithMessage(x => "Description must be less than 500 characters!");
}
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.