Laixer.EventBus 1.0.2

Event bus for ASP.NET Core projects. Define events and event handlers for inner-project signaling.

There is a newer version of this package available.
See the version list below for details.
Install-Package Laixer.EventBus -Version 1.0.2
dotnet add package Laixer.EventBus --version 1.0.2
<PackageReference Include="Laixer.EventBus" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Laixer.EventBus --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Define an event to fire:

interface IUpdateUserProfileEvent : IEvent
{
    User User { get; set; }
}

Then define an handler for the event:

class UpdateUserProfileHandler : IEventHandler<IUpdateUserProfileEvent>
{
    public Task HandleEventAsync(EventHandlerContext<IUpdateUserProfileEvent> context, CancellationToken cancellationToken = default)
    {
        // Handle event

        return Task.Completed;
    }
}

Register the event with the service collection:

public void ConfigureServices(IServiceCollection services)
{    
    services.AddEventBus()
        .AddHandler<IUpdateUserProfileEvent, UpdateUserProfileHandler>(nameof(UpdateUserProfileHandler));
}

Use the event bus to trigger the event:

public class UserOperation
{
    private readonly EventBusService _eventBus;

    public UserController(EventBusService eventBus)
    {
        _eventBus = eventBus;
    }

    public async Task Method(User user)
    {
        // Fire event for updated user profile
        await _eventBus.FireEventAsync(new UpdateUserProfileEvent
        {
            User = user
        });
    }
}

Define an event to fire:

interface IUpdateUserProfileEvent : IEvent
{
    User User { get; set; }
}

Then define an handler for the event:

class UpdateUserProfileHandler : IEventHandler<IUpdateUserProfileEvent>
{
    public Task HandleEventAsync(EventHandlerContext<IUpdateUserProfileEvent> context, CancellationToken cancellationToken = default)
    {
        // Handle event

        return Task.Completed;
    }
}

Register the event with the service collection:

public void ConfigureServices(IServiceCollection services)
{    
    services.AddEventBus()
        .AddHandler<IUpdateUserProfileEvent, UpdateUserProfileHandler>(nameof(UpdateUserProfileHandler));
}

Use the event bus to trigger the event:

public class UserOperation
{
    private readonly EventBusService _eventBus;

    public UserController(EventBusService eventBus)
    {
        _eventBus = eventBus;
    }

    public async Task Method(User user)
    {
        // Fire event for updated user profile
        await _eventBus.FireEventAsync(new UpdateUserProfileEvent
        {
            User = user
        });
    }
}

Release Notes

Include license

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.4 194 10/11/2019
1.0.2 218 8/20/2019
1.0.0 132 8/16/2019