Various common utilities
$ dotnet add package SFX.EventAggregationA simple event aggreator, that eases subscription and publishing of typed events.
Same documentation for F# programmers
The main objectives for the library is to:
SynchronizationContextThe library consists of:
IDisposableclassDiagram
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 synchronouslyTIHandleAsync<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 asynchronouslyIEventAggregator<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 aggregatorBut generics are difficult or impossible for now to render in the above
Simple usage is:
IHandle<T> or IHandleAsync<T>.SynchronizationContext