Eventor.Core 1.0.1

dotnet add package Eventor.Core --version 1.0.1
                    
NuGet\Install-Package Eventor.Core -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Eventor.Core" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Eventor.Core" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Eventor.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Eventor.Core --version 1.0.1
                    
#r "nuget: Eventor.Core, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Eventor.Core@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Eventor.Core&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Eventor.Core&version=1.0.1
                    
Install as a Cake Tool

.NET Coverage Status Nuget download

icon Eventor

Overview

Eventor serves as an event aggregator that blurs the lines between aggregator and mediator. It facilitates in-process event communication through the publisher-subscriber paradigm. Additionally, it allows the publication of events that can be processed by dynamically invoked handlers registered in an IOC container.

The library package can be seamlessly integrated into both web and desktop applications. Its inception was driven, in part, by the need for efficient in-process communication between components in Blazor Web Assembly, along with the capability to handle domain events on the backend server.

Installation

Download and install the latest version of the Eventor.Core package from nuget.org using your preferred client tool.

Example usage

The preferred approach is to register Eventor in your chosen IOC container as a singleton, thereby facilitating access to all of the functionality. However, if you do not need dynamically invoked event handlers, you can use Eventor without an IOC container.

Register the EventAggregator as preferred. Examples shown below use the Microsoft.Extensions.DependencyInjection package and Autofac IOC containers. These containers allow for both the injection of the event aggregator as a singleton service and the dynamic invocation of event handlers, which you can also register with the IOC container.

services.AddSingleton<IEventAggregator>(provider => new EventAggregator(type => provider.GetRequiredService(type)))

// Or

builder.Register(c =>
{
    var context = c.Resolve<IComponentContext>();
    return new EventAggregator(type => context.Resolve(type));
}).As<IEventAggregator>().SingleInstance();

Note: The 'EventAggregator' has both a parameterless constructor and one that accepts a Func<Type,dynamic>. This callback function allows Eventor, when publishing events, to request any IOC registered event handlers associated with the event being published. These handlers are then created and passed to an 'IEventPublisher' implementation that will invoke the handler using its publish strategy.

A client and/or component can subscribe to receive events via local event handlers using the 'Subscribe' method on the 'EventAggregator':

var eventSubscription = _eventAggregator.Subscribe<SomeEvent>(SomeEventHandler);

private async Task SomeEventHandler(SomeEvent theEvent, CancellationToken cancellationToken){\...\};

Note: Events are created by deriving from the EventBase abstract class. When you subscribe to receive events, you will be returned an 'EventSubscription'. This subscription can be used to stop receiving events by calling its 'Dispose' method. Eventor uses weak-referenced delegates. Once either the dispose method is called or the event subscription has gone out of scope, the underlying delegate handler will be removed from the managed invocation list.

Note: For Blazor WebAssembly when using 'AddScoped' / 'InstancePerLifetimeScope' or 'AddSingleton' / 'SingleInstance' ensure that you call the 'Dispose' method on any event subscriptions when you are finished with them. It is recommended to implement the IDisposable or IAsyncDisposable interface and add the calls to any event subscriptions dispose methods there. You can however call the dispose method earlier if required, and calling the dispose method multiple times has no side effects.

A client and/or component can then raise an event using the 'Publish' method, all subscribers and/or associated IOC registered event handlers will then be notified:

var someEvent = new SomeEvent(\..\); 
await _eventAggregator.Publish(someEvent, PublishMethod.FireAndForget, CancellationToken.None);

Events can be published using one of the two built-in publishing strategies, selected via the enum as shown above. Alternatively, you can provide your own publishing strategy by creating a concrete implementation of the 'IEventPublisher' interface and passing it to the publish method. For the built-in publishers, 'FireAndForget' lives up to its name and will swallow any unhandled exceptions in any receiving event handlers. On the other hand, the 'WaitForAll' option awaits a Task.WhenAll and, upon completion, will throw an 'AggregateException' if one or more unhandled exceptions occurred in any of the receiving handlers.

Note: For dynamic event handlers you simply implement the 'IEventHandler<TEvent>' where TEvent is your implementation of 'EventBase' and register it with your chosen IOC container, for example:

public class OrderProcessedEventHandler : IEventHandler<OrderProcessedEvent>
{
    //Add constructor and any injected dependencies

    public async Task Handle(OrderProcessedEvent theEvent, CancellationToken cancellationToken) {\..\}
}

// register with IOC container such as Microsoft.Extensions.DependencyInjection package or Autofac

services.AddTransient<IEventHandler<OrderProcessedEvent>, OrderProcessedEventHandler>()
// Or
builder.RegisterType<OrderProcessedEventHandler>().As<IEventHandler<OrderProcessedEvent>>().InstancePerDependency();

From the above, every time an 'OrderProcessedEvent' is published the 'OrderProcessedEventHandler' will be invoked, as will any associated event handler subscriptions.

In conjunction with the documentation on the project Wiki, it is recommended that you download the source code from the Git repository and explore the scenarios within the demo projects. These sample scenarios should answer most of your questions.

Any feedback, positive or negative, is welcome, especially surrounding scenarios/usage.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 194 4/9/2025
1.0.0 329 11/30/2023

Updated to .net 9