FlowX, a high performance and convenience package for database
$ dotnet add package FlowXFlowX is a modern library designed to simplify the creation and management of Request Flow patterns in .NET applications. This library is ideal for developers building enterprise-grade solutions who need a seamless approach to implementing CQRS (Command Query Responsibility Segregation) patterns.
Result<T> for handling success/failure scenarios.Asc, Desc, ThenBy, ThenDescBy).[!WARNING]
All FlowX* packages need to have the same version.
FlowX utilizes System.Text.Json for message serialization and deserialization. Be mindful of this when sending or receiving requests from other services.
Ensure you have the following installed:
To install the FlowX package, use the following NuGet command:
dotnet add package FlowX
Or via the NuGet Package Manager:
Install-Package FlowX
Add the FlowX to your service configuration to register OfX:
builder.Services.AddFlowX(cfg =>
{
cfg.AddModelsFromNamespaceContaining<ITestAssemblyMarker>();
cfg.AddHandlersFromNamespaceContaining<ITestAssemblyMarker>();
cfg.AddPipelines(c => c.OfType<SomeThingPipeline>(serviceLifetime));
});
AddModelsFromNamespaceContaining<T>: Registers all models located in the namespace containing the specified assembly
marker (T). Use this to automatically include models you’ve created in the same assembly..
AddHandlersFromNamespaceContaining<T> Registers all handlers from the namespace containing the specified assembly
marker (T). This ensures any handlers you’ve implemented in that assembly are properly added.
AddSqlPipelines Adds SQL pipelines for processing specific or generic requests. Customize the pipeline behavior using
the provided configuration.!
Below is a sample implementation of a CreateSomeThingHandler using FlowX(FlowX.EntityFramework sample):
public sealed class CreateSomeThingHandler(
ISqlRepository<SomeThing> sqlRepository,
IMapper mapper,
IUnitOfWork unitOfWork)
: EfCommandOneVoidHandler<SomeThing, CreateSomeThingCommand>(sqlRepository, unitOfWork)
{
protected override ICommandOneFlowBuilderVoid<SomeThing> BuildCommand(
IStartOneCommandVoid<SomeThing> fromFlow, CreateSomeThingCommand command,
CancellationToken cancellationToken)
=> fromFlow
.CreateOne(mapper.Map<SomeThing>(command))
.WithCondition(_ => None.Value)
.WithErrorIfSaveChange(SomeErrorDetail());
}
Sample pipeline:
public sealed class SomeThingPipeline : IFlowPipelineBehavior<GetSomeThingQuery, SomeThingResponse>
{
public async Task<SomeThingResponse> HandleAsync(RequestContext<GetSomeThingQuery> requestContext,
Func<Task<SomeThingResponse>> next)
{
Console.WriteLine("GetUserPipeline");
var result = await next.Invoke();
return result;
}
}
How to invoke the request:
var sender = ServiceProvider.GetRequiredService<IFlow>();
var userResult = await sender.Send(new GetUserQuery("1"));
Like the Mediator Pattern, you don't need to care about the handler and how it do. Just ExecuteAsync
Flow enables the creation of requests in a structured and intuitive way. Each flow defines a step-by-step process that ensures reliability and maintainability.
FlowX supports flexible sorting with multiple fields using a fluent API:
public sealed class GetProvincesHandler : EfQueryCollectionHandler<Province, GetProvincesQuery, ProvinceResponse>
{
protected override IQueryListFlowBuilder<Province, ProvinceResponse> BuildQueryFlow(
IQueryListFilter<Province, ProvinceResponse> fromFlow, IRequestContext<GetProvincesQuery> queryContext)
=> fromFlow
.WithFilter(null)
.WithSpecialAction(a => a.Select(x => new ProvinceResponse { Id = x.Id, Name = x.Name }))
.WithDefaultSortFields(Asc(a => a.Name).ThenDescBy(x => x.Id));
}
Available sort methods:
Asc(expression) - Sort ascending by a fieldDesc(expression) - Sort descending by a fieldThenBy(expression) - Then sort ascendingThenDescBy(expression) - Then sort descendingFor pagination queries, clients can also specify sort fields via the SortedFields parameter:
// Request with dynamic sorting
var query = new GetManyQuery(PageSize: 10, PageIndex: 1, SortedFields: "Name asc, Id desc");
Errors in FlowX are predefined, enabling consistent error messaging across your application.
We welcome contributions to FlowX! To contribute, please:
FlowX is licensed under the Apache License Version 2.0. See LICENSE for more details.
For inquiries, reach out to FlowX.
Happy coding with FlowX!
| Package Name | Description | .NET Version | Document |
|---|---|---|---|
| FlowX | FlowX core | 8.0, 9.0 | This Document |
| Data Provider | |||
| FlowX.EntityFrameworkCore | This is the FlowX extension package using EntityFramework to fetch data | 8.0, 9.0 | ReadMe |
| Transports | |||
| FlowX.Nats | FlowX.Nats is an extension package for FlowX that leverages Nats for efficient data transportation. | 8.0, 9.0 | ReadMe |
| FlowX.Azure.ServiceBus | FlowX.Azure.ServiceBus is an extension package for FlowX that leverages Azure ServiceBus for efficient data transportation. | 8.0, 9.0 | ReadMe |