LiteLib.Bus-Lite
1.0.0
dotnet add package LiteLib.Bus-Lite --version 1.0.0
NuGet\Install-Package LiteLib.Bus-Lite -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="LiteLib.Bus-Lite" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteLib.Bus-Lite --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LiteLib.Bus-Lite, 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.
// Install LiteLib.Bus-Lite as a Cake Addin
#addin nuget:?package=LiteLib.Bus-Lite&version=1.0.0
// Install LiteLib.Bus-Lite as a Cake Tool
#tool nuget:?package=LiteLib.Bus-Lite&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Bus-Lite
Bus-Lite is a small size, high performance tool for objects communication using events. Library is thread safe, written in C# and has no external dependencies.
It supports 2 different workflows:
- Notifying multiple listeners without returning any value
- Notifying single handler which returns a value
Table of contents
Features
- Sending an event to multiple listeners (synchronous, without return value)
- Sending an event to a specyfic handler (asynchronous, with return value)
- Subscribing listeners
- Removing listeners using tokens
- Registering handlers
- Removing handlers using tokens
- Removing all owner's observers at once
- Multi-thread safety
Examples
// creating an instance of an event bus
var eventBus = new EventBus();
// subscribing listener to an event
//
// using Subscribe() we can define multiple listeners for a single event
// listeners can not return any value
//
// first argument is an owner (can not be of type 'ObserverToken')(almost always 'this')
// second argument is a callback function
// method retuns token which is used to unsubscribing (so is owner)
var eventBus = new EventBus();
var token = eventBus.Subscribe<string>(this, (@event) => { /* implementation */ });
var token2 = eventBus.Subscribe(this, (string @event) => { /* implementation */ });
var token3 = eventBus.Subscribe<string>(this, new StringEventListener()); // implementation of IEventListener<string>
var token4 = eventBus.Subscribe(this, new StringEventListener()); // implementation of IEventListener<string>
// unsubscribing given listener using it's token
var eventBus = new EventBus();
// ...
var token = eventBus.Subscribe<string>(this, (@event) => { /* implementation */ });
// ...
eventBus.Remove(token);
// unsubscribing all owner's listeners
var eventBus = new EventBus();
// ...
eventBus.Subscribe<string>(this, (@event) => { /* implementation */ });
eventBus.Subscribe<int>(this, (@event) => { /* implementation */ });
// ...
eventBus.Remove(this);
// pushing event to appropriate listeners
// all required listeners will be notified
var eventBus = new EventBus();
// ...
eventBus.Subscribe<string>(this, (@event) => { /* implementation */ });
eventBus.Subscribe<string>(this, (@event) => { /* implementation */ });
// ...
eventBus.Notify("example string");
//registering handler to an event
//
// using Register() we can define single handler for a single event
// handlers can return value
//
// first argument is an owner (can not be of type 'ObserverToken')(almost always 'this')
// second argument is a callback function
// method retuns token which is used to unsubscribing (so is owner)
var eventBus = new EventBus();
var token = eventBus.Register<IEvent<string>, string>(this, async (@event) => await Task.FromResult(""));
var token2 = eventBus.Register(this, async (IEvent<string> @event) => await Task.FromResult(""));
var token3 = eventBus.Register<IEvent<string>, string>(this, new StringEventHandler()); // implementation of IEventHandler<IEvent<string>, string>
var token4 = eventBus.Register(this, new StringEventHandler()); // implementation of IEventHandler<IEvent<string>, string>
// unsubscribing given handler using it's token
var eventBus = new EventBus();
// ...
var token = eventBus.Register(this, new StringEventHandler());
// ...
eventBus.Remove(token);
// pushing event to appropriate handler
// only one handler will be notified
// call can be awaited and return a value
// if no handler was registed for en event an exception will be thrown
var eventBus = new EventBus();
// ...
eventBus.Register(this, new StringEventHandler());
// ...
var @event = new StringEvent("");
var result = await eventBus.Handle(@event);
Todos
- Write MORE Tests
- Method to temporarily stop listening without unsubscribing
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- 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 | 190 | 1/15/2023 |