FlowX 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.
- Fluent API for building Request Flows.
- Error handling mechanisms with custom error definitions.
Ensure you have the following installed:
- .NET 8.0 or higher
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.AddSqlPipelines(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 : ISqlPipelineBehavior<GetSomeThingQuery, OneOf<SomeThingResponse, Error>>
{
public async Task<OneOf<SomeThingResponse, Error>> HandleAsync(RequestContext<GetSomeThingQuery> requestContext,
Func<Task<OneOf<SomeThingResponse, Error>>> next)
{
Console.WriteLine("GetUserPipeline");
var result = await next.Invoke();
return result;
}
}
How to invoke the request:
var sender = ServiceProvider.GetRequiredService<IFlowXSender>();
var userResult = await sender.ExecuteAsync(new GetUserQuery("1"));
Like the Mediator Pattern, you don't need to care about the handler and how it do. Just ExecuteAsync
FlowX enables the creation of requests in a structured and intuitive way. Each flow defines a step-by-step process that ensures reliability and maintainability.
Errors in FlowX are predefined, enabling consistent error messaging across your application.
We welcome contributions to FlowX! To contribute, please:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request with a detailed explanation of your changes.
FlowX is licensed under the MIT License. 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 |
FlowX.EntityFrameworkCore | This is the FlowX extension package using EntityFramework to fetch data | 8.0, 9.0 | ReadMe |