https://github.com/skwasjer/rebus.fluentvalidation
Message validation using FluentValidation for Rebus.
https://github.com/skwasjer/rebus.fluentvalidation
fluentvalidation rebus
Last synced: 12 months ago
JSON representation
Message validation using FluentValidation for Rebus.
- Host: GitHub
- URL: https://github.com/skwasjer/rebus.fluentvalidation
- Owner: skwasjer
- License: apache-2.0
- Created: 2020-01-21T01:02:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-01T10:11:24.000Z (about 6 years ago)
- Last Synced: 2025-06-13T10:08:49.515Z (12 months ago)
- Topics: fluentvalidation, rebus
- Language: C#
- Size: 97.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Rebus.FluentValidation
Message validation using [FluentValidation](https://fluentvalidation.net/) for [Rebus](https://github.com/rebus-org/Rebus).
---
[](https://ci.appveyor.com/project/skwasjer/rebus-fluentvalidation)
[](https://ci.appveyor.com/project/skwasjer/rebus-fluentvalidation/build/tests)
[](https://codecov.io/gh/skwasjer/Rebus.FluentValidation)
| | | |
|---|---|---|
| `Rebus.FluentValidation` | [](https://www.nuget.org/packages/Rebus.FluentValidation/) [](https://www.nuget.org/packages/Rebus.FluentValidation/) | |
## Usage example ###
```csharp
// Create validators and register with FluentValidation using IoC container of choice.
public class MessageType1Validator : AbstractValidator
{
public MessageType1Validator()
{
RuleFor(x => ...);
}
}
// Get FluentValidation factory from IoC container.
IValidatorFactory validatorFactory = ..
// Configure Rebus handlers and options.
Configure
.With(..)
.Options(o =>
{
// Throws on Send/Publish.
o.ValidateOutgoingMessages(validatorFactory);
// Configure strategy per incoming message.
o.ValidateIncomingMessages(validatorFactory, v =>
{
// Configure how messages that failed validation should be
// handled:
// Move messages of type MessageType1 to error queue.
v.DeadLetter();
// Drop messages of type MessageType2.
v.Drop();
// Do nothing to messages of type MessageType3 (just log warn)
// allowing them to be handled normally with IHandleMessages
v.PassThrough();
});
});
// If not explicitly configured how to handle incoming messages that failed
// validation, a message will be wrapped in IValidationFailed<> and should be
// handled using custom handler logic:
public class MyService : IHandleMessages>
{
Task Handle(IValidationFailed message)
{
// Custom handler for validation failure.
}
}
```