Cogito.MassTransit.Extensions 3.1.0

dotnet add package Cogito.MassTransit.Extensions --version 3.1.0
                    
NuGet\Install-Package Cogito.MassTransit.Extensions -Version 3.1.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="Cogito.MassTransit.Extensions" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cogito.MassTransit.Extensions" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Cogito.MassTransit.Extensions" />
                    
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 Cogito.MassTransit.Extensions --version 3.1.0
                    
#r "nuget: Cogito.MassTransit.Extensions, 3.1.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 Cogito.MassTransit.Extensions@3.1.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=Cogito.MassTransit.Extensions&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Cogito.MassTransit.Extensions&version=3.1.0
                    
Install as a Cake Tool

Cogito.MassTransit.Extensions

Fan out a request to many handlers from inside a saga, and wait for all of them.

Why

MassTransit's request/response covers one request and one reply. A saga that has to ask n services and continue when the last answers has to track the outstanding set itself — correlating replies, handling faults, and timing out — which is fiddly state-machine code written the same way each time.

Install

dotnet add package Cogito.MassTransit.Extensions

Use

A multi-request keeps one state item per outstanding request on the saga, and reaches it through an IMultiRequestStateAccessor that you implement. Declare it on a state machine derived from Cogito.MassTransit.MassTransitStateMachine<TSaga>, send it from an event, and continue on Finished once every request has completed, faulted or timed out:

public class OrderStateMachine : Cogito.MassTransit.MassTransitStateMachine<OrderState>
{
    public OrderStateMachine()
    {
        InstanceState(x => x.CurrentState);
        Event(() => Submitted, x => x.CorrelateById(m => m.Message.OrderId));

        MultiRequest(() => CheckStock, saga => saga.Lines, line => line.RequestId, new LineAccessor(), c =>
        {
            c.ServiceAddress = new Uri("queue:check-stock");
            c.Timeout = TimeSpan.FromSeconds(30);
        });

        Initially(
            When(Submitted)
                .MultiRequest(CheckStock, ctx => ctx.Message.Lines.Select(l => new CheckStock(l.Sku)))
                .TransitionTo(CheckStock.Pending));

        During(CheckStock.Pending,
            When(CheckStock.Finished)
                .Then(ctx => ...));
    }

    public Event<SubmitOrder> Submitted { get; private set; }

    public MultiRequest<OrderState, LineState, CheckStock, StockChecked> CheckStock { get; private set; }
}

A state machine built without a class, through MassTransit's MassTransitStateMachine<TSaga>.New, declares it on the modifier instead, and receives the multi-request as an out parameter:

var machine = MassTransitStateMachine<OrderState>.New(cfg => cfg
    .InstanceState(x => x.CurrentState)
    .Event("Submitted", x => x.CorrelateById(m => m.Message.OrderId), out Event<SubmitOrder> submitted)
    .MultiRequest("CheckStock", saga => saga.Lines, line => line.RequestId, new LineAccessor(),
        c => c.ServiceAddress = new Uri("queue:check-stock"), out var checkStock)
    .Initially()
        .When(submitted, b => b
            .MultiRequest(checkStock, ctx => ctx.Message.Lines.Select(l => new CheckStock(l.Sku)))
            .TransitionTo(checkStock.Pending))
        .CommitActivities()
    .During(checkStock.Pending)
        .When(checkStock.Finished, b => b.Then(ctx => ...))
        .CommitActivities());

Either way, the multi-request's events and pending state are named after it: CheckStock.Finished, CheckStock.Pending and so on. A timeout needs a message scheduler configured on the bus.

Each item's outcome is reported as a MultiRequestFinishedItem with a MultiRequestItemStatus, so a partial failure is visible rather than indistinguishable from success. MultiRequestSettings covers timeouts, and RequestTimeoutExpired is raised when one elapses.

CaptureRequestExtensions and IRequestToken carry the originating request through a conversation; FaultedToExtensions routes faults, and ExceptionInfoException turns a serialised MassTransit ExceptionInfo back into a throwable exception.

License

MIT.

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. 
.NET Framework net472 is compatible.  net48 was computed.  net481 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
3.1.0 103 10/15/2026
3.0.0 94 10/10/2026
3.0.0-pre.14 69 10/10/2026
2.3.7 107 9/14/2026
2.3.6 113 9/14/2026
2.3.5 111 9/10/2026
2.3.4 1,878 5/3/2026
2.3.3 118 5/3/2026
2.3.2 127 5/3/2026
2.3.1 120 5/3/2026
2.3.0 127 5/3/2026