EventX 1.0.4

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

EventX

EventX is a lightweight, flexible event manager for C# that allows you to easily handle events, dispatch them, and register listeners. This library is perfect for implementing an event-driven architecture in your C# projects. EventX follows the JavaScript-style event listener pattern, where you can register event listeners for specific events, dispatch events, and remove listeners dynamically.

Installation

To install via NuGet:

dotnet add package EventX --version 1.0.0

Or you can manually add the package through the NuGet Package Manager in Visual Studio. Usage

Add an Event Listener

You can add an event listener to handle a specific event. Event handlers are triggered when the event is dispatched. using EventX.Core;

EventManager.AddEventListener("eventName", (args) =>
{
    // Handle the event
    Console.WriteLine("Event received with args: " + string.Join(", ", args));
});

Dispatch an Event

You can dispatch an event and pass arguments to the listeners.

using EventX.Core;

EventManager.Dispatch("eventName", "arg1", 42);

Remove an Event Listener

If you want to remove a previously registered event listener, use the Off method. using EventX.Core;

EventManager.Off("eventName", handler);

Dispatch an Event Asynchronously

You can also dispatch events asynchronously.

using EventX.Core;

await EventManager.DispatchAsync("eventName", "asyncArg", 123);

Add a Once-Only Event Listener

To add a listener that will only be triggered once, use the Once method.

using EventX.Core;

EventManager.AddEventListener("eventName", (args) =>
{
    Console.WriteLine("This will be triggered only once.");
}, IsOnce: true);

Dependency Injection (DI) Support

EventX also supports Dependency Injection (DI) and provides a fluent builder pattern to register initial event listeners.

You can easily set it up with .NET's built-in DI system using Host.CreateDefaultBuilder:

using EventX.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = Host.CreateDefaultBuilder(args)
    .ConfigureServices((context, services) =>
    {
        services.AddEventManager(builder =>
        {
            builder
                .AddListener("myevent:customevent1", args => Console.WriteLine("Dispatched customevent1"))
                .AddListener("myevent:customevent2", args => Console.WriteLine("Dispatched customevent2"));
        });
        services.AddScoped<MyCustomService>();
    })
    .Build();

This allows you to pre-register event listeners at application startup, making it easier to maintain and extend your event-driven architecture.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contribution

Contributions are welcome! Please feel free to open an issue or submit a pull request.

Contact

For questions or suggestions, please open an issue in the GitHub repository.

Happy coding with EventX!

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.4 107 4/27/2025
1.0.3 54 4/26/2025
1.0.1 53 4/26/2025
1.0.0 54 4/26/2025