FlowCore 1.1.2

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

📦 FlowCore

FlowCore is a lightweight, extensible, and modern Mediator for .NET 8+, supporting patterns such as CQRS, Pipeline Behaviors, and EF Core integration.

🎯 Main Features

  • Support for Commands, Queries, and Events
  • Pipeline Behaviors with:
    • Validation (via FluentValidation)
    • Logging with execution time
    • Caching for queries
    • Transactions with EF Core (optional)
    • Event dispatcher after execution
  • Support for multiple Handlers (multicast for events)
  • Ready for Dependency Injection
  • CQRS separation between read and write
  • Auto-registration via Scrutor

📥 Installation

dotnet add package FlowCore --version 1.1.1

⚙️ Pipeline Behaviors (execution order)

Order Behavior Function
1 LoggingBehavior Log input/output with timing
2 ValidationBehavior Validates with FluentValidation
3 CachingBehavior Cache for queries
4 TransactionScopeBehavior EF Core transaction (optional)
5 EventDispatcherBehavior Dispatches events after handler

🔧 Main Interface

public interface IFlowMediator
{
    Task<TResult> SendAsync<TResult>(ICommand<TResult> command, CancellationToken ct = default);
    Task SendAsync(ICommand<Unit> command, CancellationToken ct = default);
    Task<TResult> QueryAsync<TResult>(IQuery<TResult> query, CancellationToken ct = default);
    Task PublishAsync(IEvent @event, CancellationToken ct = default);
}

📚 Usage Examples

1️⃣ Defining a Command

public record CreateUserCommand(string Name, string Email) : ICommand<Guid>;

public class CreateUserHandler : ICommandHandler<CreateUserCommand, Guid>
{
    public Task<Guid> Handle(CreateUserCommand request, CancellationToken ct)
    {
        // Business logic
        return Task.FromResult(Guid.NewGuid());
    }
}

2️⃣ Defining a Query

public record GetUserByIdQuery(Guid Id) : IQuery<UserDto>;

public class GetUserByIdHandler : IQueryHandler<GetUserByIdQuery, UserDto>
{
    public Task<UserDto> Handle(GetUserByIdQuery request, CancellationToken ct)
    {
        // Search logic
        return Task.FromResult(new UserDto { Id = request.Id, Name = "John" });
    }
}

3️⃣ Defining an Event

public record UserCreatedEvent(Guid UserId) : IEvent;

public class UserCreatedHandler : IEventHandler<UserCreatedEvent>
{
    public Task Handle(UserCreatedEvent notification, CancellationToken ct)
    {
        // Send email, log, etc.
        return Task.CompletedTask;
    }
}

4️⃣ Registering in DI

builder.Services.AddFlowCore(cfg =>
{
    cfg.RegisterHandlersFromAssemblyOf<Program>();
});

5️⃣ Using the Mediator

public class UserService(IFlowMediator mediator)
{
    public async Task<Guid> CreateUser(string name, string email)
    {
        return await mediator.SendAsync(new CreateUserCommand(name, email));
    }

    public async Task<UserDto> GetUser(Guid id)
    {
        return await mediator.QueryAsync(new GetUserByIdQuery(id));
    }

    public async Task NotifyCreation(Guid userId)
    {
        await mediator.PublishAsync(new UserCreatedEvent(userId));
    }
}

🔐 Validation with FluentValidation

public class CreateUserValidator : AbstractValidator<CreateUserCommand>
{
    public CreateUserValidator()
    {
        RuleFor(x => x.Name).NotEmpty().MaximumLength(100);
        RuleFor(x => x.Email).EmailAddress();
    }
}

💾 Caching Configuration

builder.Services.AddFlowCore(cfg =>
{
    cfg.RegisterHandlersFromAssemblyOf<Program>();
    cfg.UseCaching(new CachingOptions
    {
        DefaultExpiration = TimeSpan.FromMinutes(5),
        CacheKeyGenerator = new CustomCacheKeyGenerator()
    });
});

🔄 Transactions with EF Core

builder.Services.AddFlowCore(cfg =>
{
    cfg.RegisterHandlersFromAssemblyOf<Program>();
    cfg.UseTransactionScope(new TransactionOptions
    {
        IsolationLevel = IsolationLevel.ReadCommitted
    });
});

🎨 Custom Behaviors

public class MyCustomBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
    public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken ct)
    {
        // Before handler
        var response = await next();
        // After handler
        return response;
    }
}

// Register
builder.Services.AddFlowCore(cfg =>
{
    cfg.RegisterHandlersFromAssemblyOf<Program>();
    cfg.AddBehavior(typeof(MyCustomBehavior<,>));
});

📄 License

This project is licensed under the MIT License.

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
2.2.3 82 7/10/2026
2.2.2 63 7/10/2026
2.2.1 66 7/9/2026
2.2.0 71 7/9/2026
1.1.3 64 6/27/2026
1.1.2 65 6/27/2026
1.1.1 69 6/23/2026
1.1.0 83 6/23/2026

- Traduzido para inglês o README
- Removido uso de dynamic para maior performance e type safety
- EF Core agora é opcional (transações são um módulo separado)
- Adicionado suporte a ICommand sem retorno (Unit)
- Corrigido CachingBehavior para tratar valores null
- Adicionada documentação XML completa