Verbytes.PassR 1.2.1

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

PassR ๐Ÿงญ

A lightweight, flexible mediator library for .NET applications โ€” designed with Clean Architecture in mind.


โœจ Overview

PassR is a minimal, fast, and extensible .NET library that enables clean separation of concerns using the Mediator pattern.
Inspired by MediatR, PassR adds support for:

  • โœ… Request/response handling (IRequest, IRequestHandler)
  • โœ… Fire-and-forget notifications (INotification, INotificationHandler)
  • โœ… Middleware pipeline behaviors (IPipelineBehavior)
  • โœ… Clean and testable architecture, built on top of dependency injection
  • โœ… Command & Query separation via ICommand, IQuery abstractions

๐Ÿ“ฆ Installation

dotnet add package Verbytes.PassR

๐Ÿ›  Setup

Register PassR and presentation services in your Program.cs:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddPresentation();
builder.Services.AddPassR(options =>
{
    options.RegisterServicesFromAssembly(typeof(CreateUserCommandHandler).Assembly);
    options.AddOpenBehavior(typeof(LoggingBehavior<,>));
});
builder.Services.AddEndpoints(Assembly.GetExecutingAssembly());

๐Ÿ›ฃ๏ธ API Pipeline Bootstrapping

You can set up the full API versioning + exception handler + Swagger pipeline with a single method:

var app = builder.Build();
 
app.UsePassRPresentation(endpointAssembly: typeof(IEndpoint).Assembly);

This configures:

  • API versioning using route segments (/api/v1/...)
  • Swagger UI with support for multiple versions
  • Automatic endpoint discovery via IEndpoint implementations
  • Custom exception middleware with problem response output

๐Ÿ“ Basic Usage

1. Define a Request

public record GetUserQuery(Guid UserId) : IQuery<UserDto>;

2. Create a Handler

public class GetUserQueryHandler : IQueryHandler<GetUserQuery, UserDto>
{
    public async ValueTask<Result<UserDto>> HandleAsync(GetUserQuery request, CancellationToken cancellationToken)
    {
        // simulate user retrieval
        return Result.Success(new UserDto(request.UserId, "burak@example.com"));
    }
}

3. Send the Request

var result = await mediator.SendAsync(new GetUserQuery(Guid.NewGuid()));

๐Ÿ” Notification Handling

public record UserCreated(Guid UserId) : INotification;

public class SendWelcomeEmailHandler : INotificationHandler<UserCreated>
{
    public ValueTask HandleAsync(UserCreated notification, CancellationToken cancellationToken)
    {
        Console.WriteLine($"Sending email to user: {notification.UserId}");
        return ValueTask.CompletedTask;
    }
}

Publish with:

await mediator.PublishAsync(new UserCreated(userId));

๐Ÿงฉ Pipeline Behaviors

public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    public async ValueTask<TResponse> HandleAsync(
        TRequest request,
        CancellationToken cancellationToken,
        RequestHandlerDelegate<TResponse> next)
    {
        Console.WriteLine($"[START] {typeof(TRequest).Name}");
        var response = await next();
        Console.WriteLine($"[END] {typeof(TRequest).Name}");
        return response;
    }
}

๐Ÿ”€ Built-in Minimal API Versioning with Swagger UI

PassR now supports automatic API versioning for Minimal APIs with seamless Swagger integration.

โœ… Features

  • Annotate your endpoint class with [ApiVersion(x)] (e.g. [ApiVersion(2)])
  • PassR dynamically detects all versions (v1, v2, v3...) without hardcoding
  • Endpoints are grouped under /api/v{version} automatically
  • Swagger UI displays version tabs for each registered version

๐Ÿš€ Example

[ApiVersion(2)]
public class PostTestV2 : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapPost("PostTest", ...)
            .WithTags("Tests")
    }
}

No need to configure versions manually. Just use:


var app = builder.Build();

app.UsePassRPresentation(Assembly.GetExecutingAssembly());

Enjoy fully dynamic, scalable API versioning with clean Swagger support.


๐Ÿ“š Interfaces Overview

Interface Purpose
IRequest<TResponse> Represents a request with a response
IRequestHandler<,> Handles a request
INotification Represents a fire-and-forget event
INotificationHandler<> Handles a notification
IPipelineBehavior<,> Middleware logic around requests
ICommand, IQuery CQRS-style abstractions
Result, Error, ValidationError Functional result pattern

๐Ÿงช Example Projects

Check out /examples/WebAPI for how to:

  • Wire up PassR into a minimal API project
  • Use commands, queries, notifications
  • Add pipeline logging
  • Validate using a behavior layer

๐Ÿ“„ License

MIT ยฉ Burak Besli

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.2.1 111 9/23/2025
1.1.7 161 6/2/2025
1.1.4 160 5/5/2025
1.0.4 160 4/30/2025
1.0.2 146 4/29/2025