MediCore 1.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package MediCore --version 1.0.0
                    
NuGet\Install-Package MediCore -Version 1.0.0
                    
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="MediCore" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MediCore" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MediCore" />
                    
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 MediCore --version 1.0.0
                    
#r "nuget: MediCore, 1.0.0"
                    
#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 MediCore@1.0.0
                    
#: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=MediCore&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MediCore&version=1.0.0
                    
Install as a Cake Tool

MediCore

A lightweight, MediatR-style CQRS mediator for .NET 8 with first-class interceptors, a service registry, and strictly segregated interfaces.

dotnet build
dotnet test
dotnet run --project samples/MediCore.Sample

Quick start

services.AddMediCore(o => o
    .RegisterHandlersFromAssemblyContaining<Program>()
    .AddDefaultInterceptors()                 // Logging -> Validation -> Transaction
    .UseTransactionManager<MyEfTransactionManager>());   // optional

// a command, its handler and its validator
public sealed record CreateOrder(string Customer) : ICommand<Guid>;

public sealed class CreateOrderHandler : ICommandHandler<CreateOrder, Guid>
{
    public Task<Guid> HandleAsync(CreateOrder cmd, CancellationToken ct) => ...;
}

public sealed class CreateOrderValidator : IValidator<CreateOrder> { ... }
services.AddScoped<IValidator<CreateOrder>, CreateOrderValidator>();

// anywhere
var id = await sender.SendAsync(new CreateOrder("Acme"));

Project layout

src/MediCore
├── Abstractions/   pure contracts, one responsibility per interface
├── Core/           Mediator (facade), RequestDispatcher (adapter), InterceptorPipeline (chain)
├── Interceptors/   Logging, Validation, Transaction
├── Publishing/     Sequential and Parallel notification strategies
├── Transactions/   TransactionScopeManager (default ITransactionManager)
├── Registry/       IServiceRegistry, scanner, options builder, AddMediCore(...)
└── Exceptions/     HandlerNotFoundException, ValidationException
samples/MediCore.Sample   console demo
tests/MediCore.Tests      xUnit tests

Interface segregation

Interface Responsibility Inject it when you...
ISender dispatch a request to one handler only send commands/queries
IPublisher publish a notification to many handlers only raise events
IMediator ISender + IPublisher need both (rare)
ICommand<T> / IQuery<T> mark write vs read requests want CQRS semantics and transaction rules
IRequestHandler / ICommandHandler / IQueryHandler handle exactly one request implement business logic
IRequestInterceptor wrap handler execution add a cross-cutting concern
IValidator<T> validate one request type validate input
ITransactionManager / ITransaction begin / commit / roll back plug in EF Core, Dapper, ADO.NET
INotificationPublisher choose HOW handlers run change the publishing strategy
IServiceRegistry read-only catalogue of what was discovered diagnostics and startup checks

Design patterns used

Pattern Where
Mediator Mediator decouples senders from handlers
Facade Mediator hides dispatching, pipeline building and publishing behind two small interfaces
Chain of Responsibility / Decorator InterceptorPipeline — each interceptor wraps the next one
Strategy INotificationPublisher (sequential / parallel), ITransactionManager
Registry ServiceRegistry is the single source of truth of handlers and interceptor order
Builder / Options MediCoreOptions fluent configuration
Adapter / Template Method RequestDispatcher<TResponse> → RequestDispatcher<TRequest,TResponse>
Flyweight (cache) dispatchers are created once per request type
Dependency Inversion everything is resolved through abstractions and the container
CQRS ICommand / IQuery split, transactions only for commands

Interceptors (formerly "pipeline behaviors")

Execution order = registration order. The first registered is the outermost.

.AddInterceptor(typeof(LoggingInterceptor<,>))     // 1st  (outermost)
.AddInterceptor(typeof(ValidationInterceptor<,>))  // 2nd
.AddInterceptor(typeof(TransactionInterceptor<,>)) // 3rd  (closest to the handler)

Write your own:

public sealed class CachingInterceptor<TRequest, TResponse> : IRequestInterceptor<TRequest, TResponse>
    where TRequest : IQuery<TResponse>          // constraint = only queries
{
    public async Task<TResponse> InterceptAsync(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken ct)
    {
        // before ...
        var response = await next();            // skip this line to short-circuit
        // after ...
        return response;
    }
}

o.AddInterceptor(typeof(CachingInterceptor<,>));

A generic constraint decides which requests an interceptor applies to. That is how TransactionInterceptor touches commands only.

Service registry

var registry = provider.GetRequiredService<IServiceRegistry>();
registry.RequestHandlers;        // every request -> handler mapping
registry.NotificationHandlers;   // every notification handler
registry.Interceptors;           // interceptors in execution order

Startup fails fast if a request has more than one handler.

Notes

  • Publish the concrete notification type (PublishAsync(new OrderPlaced(...))); handlers are resolved for the compile-time type.
  • Swap TransactionScopeManager for your own ITransactionManager to use an explicit DbTransaction or EF Core transaction.
  • Extension ideas: streaming requests, per-request interceptor ordering attributes, notification interceptors, source-generator based registration.
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.2 121 9/21/2026
1.0.1 111 9/20/2026
1.0.0 110 9/19/2026