Interlink 1.2.1

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

Interlink is a lightweight and modern mediator library for .NET, designed to decouple your code through request/response and notification patterns. Built with simplicity and performance in mind, it helps streamline communication between components while maintaining a clean architecture.


โœจ Features

  • ๐Ÿงฉ Simple mediator pattern for request/response
  • ๐Ÿ” Publish/Subscribe notification system
  • ๐Ÿ”ง Pipeline behaviors (logging, validation, etc.)
  • ๐Ÿง  Clean separation of concerns via handlers
  • ๐Ÿช Dependency injection support out of the box
  • ๐Ÿ”„ Decouples logic using handlers
  • ๐Ÿงฉ Easy registration with AddInterlink()
  • ๐Ÿš€ Lightweight, fast, and no external dependencies
  • ๐Ÿ”„ Pre and Post Processors for enhanced lifecycle control
  • โœ… Compatible with .NET 8 and .NET 9

  • Clean, intuitive API
  • No bloat โ€“ just powerful mediation
  • Perfect for CQRS, Clean Architecture, Modular Design
  • Highly extensible with behaviors and notifications

๐Ÿ“ฆ Installation

Install Interlink via NuGet:

dotnet add package Interlink

โš™๏ธ Setup

Register Interlink in your Startup.cs or Program.cs

builder.Services.AddInterlink();

You can optionally pass an Assembly:

builder.Services.AddInterlink(typeof(MyHandler).Assembly);

๐Ÿ“จ Request/Response Pattern

1. Define a request:

public class GetAllPets
{
    public record Query : IRequest<List<string>>;

    public class Handler : IRequestHandler<Query, List<string>>
    {
        public Task<List<string>> Handle(Query request, CancellationToken cancellationToken)
        {
            var pets = new List<string> { "Dog", "Cat", "Fish" };
            return Task.FromResult(pets);
        }
    }
}

2. Inject and use ISender:

[ApiController]
[Route("api/[controller]")]
public class PetController(ISender sender) : ControllerBase
{
    [HttpGet]
    public async Task<IActionResult> GetAllPets(CancellationToken cancellationToken)
    {
        var pets = await sender.Send(new GetAllPets.Query(), cancellationToken);
        return Ok(pets);
    }
}

๐Ÿ“ฃ Notifications (One-to-Many)

1. Define a notification:

public class UserCreated(string userName) : INotification
{
    public string UserName { get; } = userName;
}

2. Create one or more handlers:

public class SendWelcomeEmail : INotificationHandler<UserCreated>
{
    public Task Handle(UserCreated notification, CancellationToken cancellationToken)
    {
        Console.WriteLine($"Welcome email sent to {notification.UserName}");
        return Task.CompletedTask;
    }
}

3. Publish with IPublisher:

public class AccountService(IPublisher publisher)
{
    public async Task RegisterUser(string username)
    {
        // Save to DB...
        await publisher.Publish(new UserCreated(username));
    }
}

๐Ÿงฌ Pipeline Behaviors

Useful for logging, validation, performance monitoring, etc.

1. Define a behavior:

public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    public async Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next)
    {
        Console.WriteLine($"Handling {typeof(TRequest).Name}");
        var response = await next();
        Console.WriteLine($"Handled {typeof(TRequest).Name}");
        return response;
    }
}

Pipeline behaviors can be manually registered like this:

builder.Services.AddInterlink();
builder.Services.AddScoped(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));

๐Ÿ”„ Pre and Post Processor

1. Define a Pre and Post Processors:

public class MyRequestPreProcessor : IRequestPreProcessor<GetAllPets.Query>
{
    public Task Process(GetAllPets.Query request, CancellationToken cancellationToken)
    {
        Console.WriteLine("[PreProcessor] Processing GetAllPets request...");
        return Task.CompletedTask;
    }
}

public class MyRequestPostProcessor : IRequestPostProcessor<GetAllPets.Query, List<Pet>>
{
    public Task Process(GetAllPets.Query request, List<Pet> response, CancellationToken cancellationToken)
    {
        Console.WriteLine("[PostProcessor] Processing GetAllPets response...");
        return Task.CompletedTask;
    }
}

Pre and Post Processors are automatically registered when you call AddInterlink().


๐Ÿ“ฆ API Overview

IRequest<TResponse>

public interface IRequest<TResponse> { }

IRequestHandler<TRequest, TResponse>

public interface IRequestHandler<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken);
}

INotification

public interface INotification { }

INotificationHandler<TNotification>

public interface INotificationHandler<TNotification>
    where TNotification : INotification
{
    Task Handle(TNotification notification, CancellationToken cancellationToken);
}

ISender

public interface ISender
{
    Task<TResponse> Send<TResponse>(IRequest<TResponse> request, CancellationToken cancellationToken = default);
}

IPublisher

public interface IPublisher
{
    Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default)
        where TNotification : INotification;
}

IPipelineBehavior<TRequest, TResponse>

public delegate Task<TResponse> RequestHandlerDelegate<TResponse>();

public interface IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    Task<TResponse> Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate<TResponse> next);
}

IRequestPreProcessor<TRequest>

public interface IRequestPreProcessor<TRequest>
{
    Task Process(TRequest request, CancellationToken cancellationToken);
}

IRequestPostProcessor<TRequest, TResponse>

public interface IRequestPostProcessor<TRequest, TResponse>
{
    Task Process(TRequest request, TResponse response, CancellationToken cancellationToken);
}

๐Ÿ” Example Use Case

  • CQRS: Use IRequest<TResponse> for Queries and Commands
  • Event-Driven architecture: Use INotification for broadcasting domain events
  • Middleware-style behaviors: Add IPipelineBehavior for logging, validation, caching, etc.

๐Ÿš€ Roadmap

โœ… v1.0.0 โ€” Core Mediator Basics (Released)

  • Basic IRequest<TResponse> and IRequestHandler<TRequest, TResponse>
  • ISender for sending requests
  • AddInterlink() for automatic DI registration
  • Clean, lightweight design
  • Only .NET 9 support

โœ… v1.0.1 โ€” Core Mediator Basics (Released)

  • Basic IRequest<TResponse> and IRequestHandler<TRequest, TResponse>
  • ISender for sending requests
  • AddInterlink() for automatic DI registration
  • Clean, lightweight design
  • .NET 8+ support

โœ… v1.1.0 โ€” Notifications & Pipelines (Released)

  • INotification and INotificationHandler<TNotification>
  • IPublisher for event broadcasting
  • IPipelineBehavior<TRequest, TResponse> support
  • Enhanced AddInterlink() with scanning and registration for notifications and pipelines
  • Updated documentation and examples
  • .NET 8+ support

โœ… v1.2.0 โ€” Pre/Post Processors (Released)

  • IRequestPreProcessor<TRequest> interface
  • IRequestPostProcessor<TRequest, TResponse> interface
  • Pre and post hooks for request lifecycle
  • Optional unit-of-work behaviors

โœ… v1.2.1 โ€” Fix Critical Bugs (Released)

  • Fix critical bugs in IPipelineBehavior<TRequest, TResponse>

๐Ÿ”œ v1.3.0 โ€” Performance & Customization

  • Handler resolution caching (delegate-based)
  • Custom service factory injection support
  • Pipeline ordering via attributes or configuration
  • Assembly scanning filters by namespace or attribute

๐ŸŒ v1.4.0 โ€” Extensions

  • Interlink.Extensions.Logging โ€” built-in logging behavior
  • Interlink.Extensions.Validation โ€” integration with FluentValidation
  • Interlink.AspNetCore โ€” model binding & filters for ASP.NET Core

๐Ÿงช v1.5.0 โ€” Developer Experience

  • Source generator / Roslyn analyzer for missing handler detection
  • Code snippets and templates for common patterns
  • Custom exception types (e.g., HandlerNotFoundException)

๐Ÿ“… Future Ideas

  • Request cancellation and timeout behaviors
  • Metrics collection and tracing support
  • Dynamic or externalized pipeline config (e.g., JSON-based)

Stay tuned for more updates! Contributions and suggestions are welcome. โœจ

๐Ÿ“œ License

MIT License ยฉ ManuHub


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 is compatible.  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. 
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.2.1 79 5/2/2025
1.2.0 77 4/26/2025
1.1.0 84 4/19/2025
1.0.1 197 4/15/2025
1.0.0 181 4/15/2025