Verbytes.PassR
1.2.1
dotnet add package Verbytes.PassR --version 1.2.1
NuGet\Install-Package Verbytes.PassR -Version 1.2.1
<PackageReference Include="Verbytes.PassR" Version="1.2.1" />
<PackageVersion Include="Verbytes.PassR" Version="1.2.1" />
<PackageReference Include="Verbytes.PassR" />
paket add Verbytes.PassR --version 1.2.1
#r "nuget: Verbytes.PassR, 1.2.1"
#:package Verbytes.PassR@1.2.1
#addin nuget:?package=Verbytes.PassR&version=1.2.1
#tool nuget:?package=Verbytes.PassR&version=1.2.1
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 | Versions 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. |
-
net8.0
- Asp.Versioning.Abstractions (>= 8.1.0)
- Asp.Versioning.Http (>= 8.1.0)
- Asp.Versioning.Mvc (>= 8.1.0)
- Asp.Versioning.Mvc.ApiExplorer (>= 8.1.0)
- Microsoft.Extensions.DependencyInjection (>= 8.0.1)
- Swashbuckle.AspNetCore (>= 8.1.1)
- Swashbuckle.AspNetCore.Swagger (>= 8.1.1)
- Swashbuckle.AspNetCore.SwaggerGen (>= 8.1.1)
- Swashbuckle.AspNetCore.SwaggerUI (>= 8.1.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.