InlineEvents.Net 1.0.4

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

InlineEvents.Net

InlineEvents.Net is a sequential event-routing framework for .NET, built for tasks that require an immediate response following an event. It is the ideal choice for scenarios where background processing is too risky or complex, ensuring that all application rules are satisfied before the calling thread returns.

Core Philosophy

Unlike traditional message buses that favor eventual consistency, InlineEvents.Net focuses on Immediate Consistency. It ensures that your side effects (Application Rules) are executed in the same execution context and database transaction as your main logic.

Installation

To install InlineEvents.Net, run the following command in your project directory:

dotnet add package InlineEvents.Net

Usage

In your Program.cs, register InlineEvents.Net with the service collection:

// Program.cs

// 1. Register the Core InlineEvents.Net Library
// This finds all IEventHandlerInline<T> classes and registers the Dispatcher (Singleton)
builder.Services.AddInlineEvents(); 

// 2. Register the Specific Publisher Abstraction (Optional)
// This is the gateway the application services will use. We use Scoped for typical web requests.
builder.Services.AddScoped<ILoginEventPublisher, LoginEventPublisher>();

// 3. Create event type
// The Event Type
public record UserLoggedIn(string UserId);

// 4. Create publisher interface with implementation
// The Publisher Interface (Specific to the Login Event)

public interface ILoginEventPublisher
{
    Task PublishAsync(UserLoggedIn @event);
}

// The Publisher Implementation (Consumes the dispatcher)
public class LoginEventPublisher(InlineEventDispatcher dispatcher) : ILoginEventPublisher
{
    public Task PublishAsync(UserLoggedIn @event) => dispatcher.Dispatch(@event);
}

### Handler Ordering (Optional)

By default, handlers just implement `IEventHandlerInline<TEvent>` 

// Classes for the Unit Test Scope (can be defined inside your test class)

public record UserLoggedIn(string UserId);

public class ExecutionLog
{
	public List<string> Sequence { get; } = [];
}

// Handler implementations used for mocking:
public class MockHandlerA(ExecutionLog log) : IEventHandlerInline<UserLoggedIn>, ISequenceHandlerInline
{
	public int Order => 100; // Low Priority
	public Task HandleInline(UserLoggedIn @event) 
	{ 
		log.Sequence.Add("Handler A (Order 100)"); 
		return Task.CompletedTask; 
	}
}

public class MockHandlerB(ExecutionLog log) : IEventHandlerInline<UserLoggedIn>, ISequenceHandlerInline
{
	public int Order => -100; // High Priority
	public Task HandleInline(UserLoggedIn @event) 
	{ 
		log.Sequence.Add("Handler B (Order -100)"); 
		return Task.CompletedTask; 
	}
}

Test

[Fact]
public async Task LoginPublisher_WithOrderedHandlers_ExecutesInCorrectSequence()
{
    // Arrange
    var log = new ExecutionLog();
    var mockResolver = new Mock<IHandlerResolver>();

    // 1. Create Handlers. Deliberately unsorted in the array.
    var unsortedHandlers = new IEventHandlerInline<UserLoggedIn>[]
    {
        new MockHandlerA(log),
        new MockHandlerB(log)
    };

    // 2. Setup the mock Resolver to return the unsorted list 
    // when the dispatcher asks for handlers of type UserLoggedIn.
    mockResolver
        .Setup(r => r.GetHandlers<UserLoggedIn>())
        .Returns(unsortedHandlers);

    // 3. Instantiate the Dispatcher, injecting the mock resolver.
    var dispatcher = new InlineEventDispatcher(mockResolver.Object);

    // Act
    await dispatcher.Dispatch(new UserLoggedIn("test-user"));

    // Assert
    // Verify that Handler B (Order -100) ran before Handler A (Order 100).
    Assert.Equal(2, log.Sequence.Count);
    Assert.Equal("Handler B (Order -100)", log.Sequence[0]);
    Assert.Equal("Handler A (Order 100)", log.Sequence[1]);
}

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 168 12/13/2025
1.0.3 163 12/13/2025
1.0.2 117 12/12/2025
1.0.1 153 12/12/2025 1.0.1 is deprecated because it has critical bugs.
1.0.0 152 12/12/2025 1.0.0 is deprecated because it has critical bugs.