Giter Site home page Giter Site logo

rebus.fluentvalidation's Introduction

Rebus.FluentValidation

Message validation using FluentValidation for Rebus.


Build status Tests codecov

Rebus.FluentValidation NuGet NuGet

Usage example

// Create validators and register with FluentValidation using IoC container of choice.
public class MessageType1Validator : AbstractValidator<MessageType1>
{
    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<MessageType1>();
            // Drop messages of type MessageType2.
            v.Drop<MessageType2>();
            // Do nothing to messages of type MessageType3 (just log warn)
            // allowing them to be handled normally with IHandleMessages<MessageType3>
            v.PassThrough<MessageType3>();
        });
    });

// 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<IValidationFailed<MessageType4>>
{
    Task Handle(IValidationFailed<MessageType4> message)
    {
        // Custom handler for validation failure.
    }
}

rebus.fluentvalidation's People

Contributors

skwasjer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.