This library implements a variation of the eventaggregator pattern.
- Event cancelling
- Subscription priorites
- Dispatching in specified threads
This library is also available as .NET 8.0 / .NET 9.0 library from NuGet.
PM> Install-Package Micky5991.EventAggregator
- .NET 8 / .NET 9
- Microsoft.Extensions.DependencyInjection.Abstractions 9.0+
- Microsoft.Extensions.Logging.Abstractions 9.0+
- System.Collections.Immutable 9.0+
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();
All have to implement the interface Micky5991.EventAggregator.Interfaces.IEvent
.
To create your first event you just have to inherit from the abstract class Micky5991.EventAggregator.Elements.EventBase
.
Data changing events implement the interface Micky5991.EventAggregator.Interfaces.IDataChangingEvent
and prevent any subscribers to subscribe from other ThreadTargets than PublishersThread.
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
.
You can find a sample project in here.
MIT License
Copyright (c) 2022-2024 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.