Giter Site home page Giter Site logo

xer.cqrs.eventstack.extensions.attributes's Introduction

Xer.Cqrs.EventStack.Extensions.Attributes

Attribute registration extension for Xer.Cqrs.EventStack

Build

Branch Status
Master Build status
Dev Build status

Nuget

NuGet

Installation

You can simply clone this repository, build the source, reference the dll from the project, and code away!

Xer.Cqrs.EventStack.Extensions.Attributes library is available as a Nuget package:

NuGet

To install Nuget packages:

  1. Open command prompt
  2. Go to project directory
  3. Add the packages to the project:
    dotnet add package Xer.Cqrs.EventStack.Extensions.Attributes
  4. Restore the packages:
    dotnet restore

Event Handler Attribute Registration

// Example event.
public class ProductRegisteredEvent
{
    public int ProductId { get; }
    public string ProductName { get; }

    public ProductRegisteredEvent(int productId, string productName)
    {
        ProductId = productId;
        ProductName = productName;
    }
}

// Example event handlers.
public class ProductRegisteredEventHandlers : IEventHandler<ProductRegisteredEvent>
{
    // Sync event handler.
    [EventHandler]
    public void Handle(ProductRegisteredEvent @event)
    {
        System.Console.WriteLine($"ProductRegisteredEventHandler handled {@event.GetType()}.");
    }
    
    // Async event handler.
    [EventHandler]
    public Task SendEmailNotificationAsync(ProductRegisteredEvent @event, CancellationToken ct)
    {
        System.Console.WriteLine($"Sending email notification...");
        return Task.CompletedTask;
    }
}
// Event Handler Registration.
public EventDelegator RegisterEventHandlers()
{
    // MultiMessageHandlerRegistration allows registration of a multiple message handlers per message type.
    var registration = new MultiMessageHandlerRegistration();

    // Register all methods with [EventHandler] attribute.
    registration.RegisterEventHandlerAttributes(() => new ProductRegisteredEventHandlers(new ProductRepository());

    // Build the event delegator.
    IMessageHandlerResolver resolver = registration.BuildMessageHandlerResolver();
    return new EventDelegator(resolver);
}

xer.cqrs.eventstack.extensions.attributes's People

Contributors

joel-jeremy avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

xer.cqrs.eventstack.extensions.attributes's Issues

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.