Skip to content

🛎️ Type-safe C# implementation of the EventAggregator pattern

License

Notifications You must be signed in to change notification settings

Micky5991/EventAggregator

Repository files navigation

EventAggregator

This library implements a variation of the eventaggregator pattern.

Features

  • Event cancelling
  • Subscription priorites
  • Dispatching in specified threads

NuGet Package

This library is also available as .NET Standard 2.1 library from NuGet.

PM> Install-Package Micky5991.EventAggregator

Getting Started

Requirements

Registration

In order to use this library, you need to first register the IEventAggregator to your IServiceCollection.

return new ServiceCollection()

    .AddSingleton<IEventAggregator, EventAggregatorService>() // Add this line to your registration chain...
    .AddScoped<IEventAggregator, EventAggregatorService>() // ... or this one if you want to scope it

    .BuildServiceProvider();

Create your first event

All have to implement the interface Micky5991.EventAggregator.Interfaces.IEvent.

Simple events

To create your first event you just have to inherit from the abstract class Micky5991.EventAggregator.Elements.EventBase.

Data changing events

Data changing events implement the interface Micky5991.EventAggregator.Interfaces.IDataChangingEvent and prevent any subscribers to subscribe from other ThreadTargets than PublishersThread.

Cancellable events

Cancellable events implement Micky5991.EventAggregator.Interfaces.ICancellableEvent which enable cancellation for other handlers and to react after the publish by the publisher.

All rules from the data changing events also apply.

To create cancellable event you just have to inherit from the abstract class Micky5991.EventAggregator.Elements.CancellableEventBase.

Example

You can find a sample project in here.

License

MIT License

Copyright (c) 2022-2023 Micky5991

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.