Skip to content

Lovrenc/SimpleEventBus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleEventBus

This is very basic Event Bus implementation written in c#.

USAGE

Create a new instance of an event bus.

Bus bus = new Bus();

PUBLISHING

To publish an event use post method like so:

bus.Post(new LanistersSlainedEvent(5));

You can use whatever object you wish as event parameter;

SUBSCRIBING

To subscribe to an event annotate a method with [Subscribe] annotation. Subscription method must return void and only use one parameter. Below you can see an example of an subscription method that listens for events that pass LanistersSlainedEvent parameter.

[Subscribe]
public void WhateverNameYouWant(LanistersSlainedEvent e)
{
    //Do something
}

One more thing you have to do, for object to start listening for bus events is calling Register method.

bus.Register(this);

When Register is called, Bus will collect subscription functions and add them to its collection. To cancel the subscriptions you must call Unregister. You should also call Unregister when disposing of class.

Sample

Solution also contains SimpleBusSample which is a Windows Forms project that enables you to add/remove TestClass objects, which subscribe to certain events, etc. All subscribe functions log to Console output.

About

Simple event bus implementation in .net.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages