NetModules 1.3.8
dotnet add package NetModules --version 1.3.8
NuGet\Install-Package NetModules -Version 1.3.8
<PackageReference Include="NetModules" Version="1.3.8" />
<PackageVersion Include="NetModules" Version="1.3.8" />
<PackageReference Include="NetModules" />
paket add NetModules --version 1.3.8
#r "nuget: NetModules, 1.3.8"
#addin nuget:?package=NetModules&version=1.3.8
#tool nuget:?package=NetModules&version=1.3.8
NetModules: A Scalable, Abstract Event-Driven Modular Framework
NetModules is an open-source architecture designed for constructing scalable, abstract, event-driven modular systems. Initially conceived as a basic demonstration of the Managed Extensibility Framework (MEF), it has since evolved beyond MEF to provide a robust and flexible architecture for developing cross-platform, plugin-based applications.
Why NetModules?
Modern applications demand adaptability and modularity, and NetModules delivers precisely that by enforcing a strict event-handling paradigm. It allows developers to design highly scalable systems where:
- Event: Strictly adhere to a predefined interface.
- Module: Declare the capability to handle specific Event types.
- ModuleHost: Serves as intermediary, ensuring efficient communication and delegation of event-handling responsibilities.
Deferred Responsibility & Scalability
This architecture simplifies application scaling and future-proofing—modifications only require changes within the event-handling modules rather than a complete system overhaul.
Example: Logging System Upgrade
Imagine your application currently logs data to a local file system. To migrate to an external logging service, instead of modifying every Module that logs data, you simply build or update a dedicated logging Module. Existing modules continue logging events as usual, unaware of the underlying change.
This follows the principle of deferred responsibility a Module raises an Event requesting data or a function call, but it does not need to handle the request itself or understand how it is processed. Instead, another Module, designed to handle that Event type, receives and processes the request, ensuring flexibility and separation of concerns.
Example: Data Requests Between Modules
A Module may trigger an Event requesting certain data. This Module does not need to know where the data comes from or how it is processed—its only concern is receiving the required response. Another Module is responsible for handling the request and determining how and where the data is fetched or computed.
Key Features
- Abstract Event Handling: Events conform to an interface, ensuring consistency and interoperability.
- Modular Design: Modules register their event-handling capabilities dynamically.
- Scalability & Future Development: Easily replace or modify event-handling modules without affecting the broader system.
- Cross-Platform Compatibility: Designed to function across any .NET-supported platform.
Getting Started
Installation
To use NetModules in your project, simply add the library via NuGet Package Manager:
Install-Package NetModules
Quick Examples
Here's a basic demonstration of how to use NetModules:
Declaring an Event
This example demonstrates an event class inheriting from the Event<I, O> structure.
public class ExampleEventInput : IEventInput {}
public class ExampleEventOutput : IEventOutput {}
public class ExampleEvent : Event<ExampleEventInput, ExampleEventOutput>
{
/// <summary>
/// Your event name should be as unique as possible, as this can be used to identify and instantiate events via ModuleHost where required.
/// Think of how Android Package naming works. E.g. "com.yourdomain.yourpackagename"
/// </summary>
public override EventName Name { get; } = "NetModules.GitHub.ExampleEvent";
}
Handling an Event with a Module
A basic example module that handles the above Event.
using NetModules.Events;
using NetModules.Interfaces;
[Module(Description = "A basic module for demonstration purposes.")]
public class ExampleModule : Module
{
public override bool CanHandle(IEvent e)
{
return e is ExampleEvent;
}
public override void Handle(IEvent e)
{
if (e is ExampleEvent example)
{
// Do something with the your custom event Input and set any custom event Output where required.
example.Handled = true;
}
}
}
Creating and Loading a Module Host
A ModuleHost is required to manage and dispatch events to loaded modules.
using NetModules;
class BasicModuleHost : ModuleHost
{
}
// Create a new module host
ModuleHost host = new BasicModuleHost();
// Load available modules
host.Modules.LoadModules();
Dispatching an Event
Once the ModuleHost has been initialized, events can be dispatched for handling.
using NetModules;
// Create a new chat event
var exampleEvent = new ExampleEvent
{
Input = new ExampleEventInput()
};
host.Handle(exampleEvent);
Every Module that is loaded into a loaded a ModuleHost has access to the ModuleHost via the this.Host
property. This means that any Module can dispatch any Event through this.Host.Handle
and the event will be sent to another handling Module for processing.
Additional Examples & Advanced Usage
Explore the NetModules.ChatModule, which showcases the framework's modular approach through a chatbot implementation. The example demonstrates Event handling using the NetModules.ChatModule.Events.ChatModuleEvent and the IEvent interface.
There are other examples in the repository, including a simle Console logging Module (BasicConsoleLoggingModule) that handles the internal LoggingEvent and outputs to Console, and a basic Module that demonstrates how to work with the CancellableEvent.
For more detailed guidance and examples, visit our repository wiki or our website (coming soon).
Full documentation coming soon!
Contributing
We welcome contributions! To get involved:
- Fork NetModules, make improvements, and submit a pull request.
- Code will be reviewed upon submission.
- Join discussions via the issues board.
License
NetModules is licensed under the MIT License, allowing unrestricted use, modification, and distribution. If you use NetModules in your own project, we’d love to hear about your experience, and possibly feature you on our website!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. 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. |
-
net6.0
- No dependencies.
NuGet packages (5)
Showing the top 5 NuGet packages that depend on NetModules:
Package | Downloads |
---|---|
NetModules.Settings.LocalSettings
A basic settings module that loads local configuration files into memory. This module handles the NetModules.Events.GetSettingEvent event. Configuration files must be JSON object formatted with a filename that starts with the module's namespace, followed by the module's name, and ending with a .json extension. |
|
NetModules.Logging.LocalLogging
A basic logging module. This module writes any NetModules.LoggingEvent data to the console output where available and also writes logs to a file in the Module.WorkingDirectory path using log rotation. |
|
NetModules.Cache.Events
This package contains events that can be referenced and handled by an event caching module to return a cached event output. Event caching modules can handle event caching silently and automatically, but can also handle the events in this pacage directly if an event is raised by another module. A usage example could be peer-to-peer module event requests, where a peer may request a cache copy from another peer. |
|
NetModules.Cache.MemoryCache
A basic cache module that uses an in-memory mechanism to store event output to a cache, using the event name, input, and optional metadata as a storage and lookup identifier. |
|
NetModules.Logging.LocalLogging.Events
This package contains events that are used with the LocalLogging module. |
GitHub repositories
This package is not used by any popular GitHub repositories.