SFX.EventAggregation 2.0.35

dotnet add package SFX.EventAggregation --version 2.0.35                
NuGet\Install-Package SFX.EventAggregation -Version 2.0.35                
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="SFX.EventAggregation" Version="2.0.35" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SFX.EventAggregation --version 2.0.35                
#r "nuget: SFX.EventAggregation, 2.0.35"                
#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.
// Install SFX.EventAggregation as a Cake Addin
#addin nuget:?package=SFX.EventAggregation&version=2.0.35

// Install SFX.EventAggregation as a Cake Tool
#tool nuget:?package=SFX.EventAggregation&version=2.0.35                

event-aggregation (C#)

A simple event aggreator, that eases subscription and publishing of typed events.

Same documentation for F# programmers

The main objectives for the library is to:

  • Facilitate a simple event aggregator, to which:
    • Subscribers implementing either synchronous or asynchronous consumption can subscribe to published event
    • Publishers can out of band publish messages to subscribers
  • Utilizing loose coupling. This is done by:
    • Having the event aggregator not holding on to subscribers. The event aggregator does this via weak references, such that subscribers can go away silently
    • Utilizing TPL dataflow action blocks to act as mail boxes for messages
  • Let subscribers determine whether they want to receive messages in order or not. This is done be configuring the TPL dataflow action blocks' level of parallelism
  • Let subscribers determine whether they want to be notified as direct calls or inside a provided SynchronizationContext

The library consists of:

  • Three interfaces
  • Two types implementing one of the interfaces and also IDisposable
classDiagram
IDisposable <|-- IEventAggregator
IEventAggregator <|-- EventAggregator
IDisposable <|-- Subscription

class IHandle {
    Handle(message: T)
}
class IHandleAsync {
    HandleAsync(message: T) : Task
}

class IEventAggregator {
    Subscribe(subscriber: IHandle, synchronizationContext: SynchronizationContext, serializeNotification: bool) : IDisposable
    SubscribeAsync(subscriber: IHandleAsync, synchronizationContext: SynchronizationContext, serializeNotification: bool) : IDisposable
    Publish(message: T)
}

class EventAggregator {
    Subscribe(subscriber: IHandle, synchronizationContext: SynchronizationContext, serializeNotification: bool) : Subscription
    SubscribeAsync(subscriber: IHandleAsync, synchronizationContext: SynchronizationContext, serializeNotification: bool) : Subscription
    Publish(message: T)
    Finalize()
}

The interfaces and some of the classes are actual generic on the type of message to publish via the event-aggregator:

  • IHandle<T> is a generic interface with a single method:
    • Handle(message: T). This interface is implemented by subscribers who want to be notified with messages of type T synchronously
  • IHandleAsync<T> is a generic interface with a single method:
    • HandleAsync(message: 'T). This interface is implemented by subscribers who want to be notified with messages of type T asynchronously
  • IEventAggregator<T> is a generic interface, that consumes either IHandle<T> or IHandleAsync<T> when subscription occurs (Subscribe or SubscribeAsync) and messages of type 'a when publishing. Subscribing returns an IDisposable, which is actually a Subscription, which upon disposal will remove the subscription from the event aggregator

But generics are difficult or impossible for now to render in the above

Simple usage is:

  • Create an instance of an event aggregator. Keep it around till it's not needed anymore.
  • Create appropriate instances of subscribers - that is instances of types, that inherit from either IHandle<T> or IHandleAsync<T>.
  • Have the various subscribers subscribe appripriately:
    • If a synchronization context is required - ie. UI components - provide a valid SynchronizationContext
    • Decide whether messages should be sent in order or not: that is the last boolean flag in the subscribe methods.
  • When subscribers go away, consider disposing of the subscription. This will eventually happen later during finalization if this is forgotten.
  • When the event aggregator is no longer needed, dispose it. If forgotten, the finalizer will take care of it
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.35 208 6/12/2023
2.0.34 153 6/12/2023
2.0.33 151 6/12/2023
2.0.32 163 6/12/2023
2.0.28 157 6/12/2023
2.0.27 169 6/12/2023
2.0.26 156 5/7/2023
2.0.25 156 5/6/2023
2.0.24 155 5/6/2023
2.0.22 181 5/6/2023
2.0.21 171 5/6/2023
2.0.20 175 5/6/2023
2.0.19 166 5/6/2023
2.0.18 137 5/6/2023
2.0.17 168 5/2/2023
2.0.15 147 5/2/2023
1.0.35 473 9/11/2020
1.0.34 518 1/17/2020
1.0.33 497 1/17/2020