FIFOFridge.EventAggregator 1.0.0

Requires NuGet 2.5 or higher.

dotnet add package FIFOFridge.EventAggregator --version 1.0.0
                    
NuGet\Install-Package FIFOFridge.EventAggregator -Version 1.0.0
                    
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="FIFOFridge.EventAggregator" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FIFOFridge.EventAggregator" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="FIFOFridge.EventAggregator" />
                    
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 FIFOFridge.EventAggregator --version 1.0.0
                    
#r "nuget: FIFOFridge.EventAggregator, 1.0.0"
                    
#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 FIFOFridge.EventAggregator@1.0.0
                    
#: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=FIFOFridge.EventAggregator&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=FIFOFridge.EventAggregator&version=1.0.0
                    
Install as a Cake Tool

EventAggregator

Simple EventAggregator implementation.

Basic usage

    // 0) Create event
    public class ClientAddedEvent : EventBase //require EventBase as base class
    {
        public ClientAddedEvent(Client client) : base()
        {
            this.client = client;
        }

        public Client client;
    }

    // 1) Register type of event, for publishing(sending) purposes
    EventAggregator.Instance.RegisterSubscribableEvent(typeof(ClientAddedEvent));

    // 2) Publishing (sending)
    public class Sender
    {
        public void DoSomeStuffAndPublishResult(Client client)
        {
            // {...}
            var event = new ClientAddedEvent(client);       //create event
            EventAggregator.Instance.Publish(this, event);  //publish, dont care about recivers
        }
    }
    
    // 3) Reciving
    public Reciver() : ISubscriber // Implement ISubscriber
    {   
        public Reciver()
        {
            EventAggregator.Instance.Subscribe<ClientAddedEvent>(this); //register event type to subsribe, and self as subscriber
        }
        
        // ISubscriber implemention:
        
        public void OnRecive<T>(object sender, T event)
        {
            if(EventAggregator.Instance.AreEventsTypesEqual<T, ClientAddedEvent>())//check is it our event
            {
                var clientEvent = event as ClientAddedEvent;
                
                // {...}
                // do stuff
                // {...}
            }
        }
    }

Lot of events to recive...

    public Reciver() : ISubscriber // Implement ISubscriber
    {   
        public Reciver()
        {
            EventAggregator.Instance.SubscribeRange(this, new Type[] 
                                                                    {
                                                                        typeof(Event0),
                                                                        typeof(Event1),
                                                                        typeof(Event2),
                                                                        typeof(Event3),
                                                                        typeof(Event4),
                                                                        typeof(Event5),
                                                                        // {...}
                                                                    });
        }
        
        public void OnRecive<T>(object sender, T event)
        {
            // {...}
        }
    }
Check examples
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has 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.0 1,415 2/21/2018