DurableMediator.OutOfProcess
3.0.0-preview
See the version list below for details.
dotnet add package DurableMediator.OutOfProcess --version 3.0.0-preview
NuGet\Install-Package DurableMediator.OutOfProcess -Version 3.0.0-preview
<PackageReference Include="DurableMediator.OutOfProcess" Version="3.0.0-preview" />
paket add DurableMediator.OutOfProcess --version 3.0.0-preview
#r "nuget: DurableMediator.OutOfProcess, 3.0.0-preview"
// Install DurableMediator.OutOfProcess as a Cake Addin #addin nuget:?package=DurableMediator.OutOfProcess&version=3.0.0-preview&prerelease // Install DurableMediator.OutOfProcess as a Cake Tool #tool nuget:?package=DurableMediator.OutOfProcess&version=3.0.0-preview&prerelease
Durable Mediator
Durable Mediator is an extension to the Durable Task library which allows for running MediatR Requests as activities in orchestrations without any complex ceremony.
Getting started
To get started with running orchestrations which call MediatR Requests as activities, which are called "Workflows", follow these steps:
First start by defining a workflow request:
public record WorkflowRequest(Guid SomeId) : IWorkflowRequest
{
public string WorkflowName => "Human readable workflow name";
public string InstanceId => SomeId.ToString();
};
Also, create a IRequest
that needs to be called from the workflow:
public record MediatorRequest(Guid SomeId) : IRequest;
Create a request handler that handles this MediatR request:
public class MediatorRequestHandler : IRequestHandler<MediatorRequest>
{
private readonly ILogger<MediatorRequestHandler> _logger;
public RequestAHandler(ILogger<MediatorRequestHandler> logger)
{
_logger = logger;
}
public Task<Unit> Handle(MediatorRequest request, CancellationToken cancellationToken)
{
_logger.LogInformation("Processing RequestA");
return Task.FromResult(Unit.Value);
}
}
Create a workflow that handles the WorkflowRequest
:
public class ExampleWorkflow : IWorkflow<WorkflowRequest, Unit>
{
private readonly ILogger<ABCWorkflow> _logger;
public ExampleWorkflow(ILogger<ABCWorkflow> logger)
{
_logger = logger;
}
public async Task<Unit> OrchestrateAsync(IWorkflowExecution<WorkflowRequest> execution)
{
var logger = execution.OrchestrationContext.CreateReplaySafeLogger(_logger);
logger.LogInformation("Start with workflow");
await execution.ExecuteAsync(new MediatorRequest(execution.Request.SomeId));
logger.LogInformation("Workflow done");
return Unit.Value;
}
}
Create a Azure Function that triggers this workflow:
public static class WorkflowTrigger
{
[FunctionName(nameof(WorkflowTrigger))]
public static async Task<IActionResult> TriggerOrchestratorAsync(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "workflow")] HttpRequestMessage req,
[Workflow] IWorkflowStarter starter)
{
var startDetails = await starter.StartNewAsync(new WorkflowRequest(Guid.NewGuid()));
return new AcceptedResult("", startDetails);
}
}
In your function app startup, add the required services by including builder.AddDurableMediator(typeof(Startup));
.
When running your function app you will see that next to the WorkflowTrigger Http Trigger function, an
Orchestration Trigger function called "WorkflowRequest" and a "DurableMediatorEntity" Entity Trigger
function are added. When http function triggers the start of the workflow, the orchestration function
will orchestrate the workflow and invoke ExampleWorkflow
. Each call to the execution.ExecuteAsync
will trigger the DurableMediatorEntity to execute the MediatR Request in a separate activity after which
the orchestration resumes. No more calling context.CallActivity
and guessing what parameters to pass in.
The execution
exposes the IDurableOrchestrationContext
from the Durable Task library, giving full access
to creating timers for durable delays, locking entities for critical sections, or wait for external events.
The execution
also exposes methods from ISubWorkflowOrchestrator
, which allows workflows to initiate other workflows,
and even await their responses, making it easy to compose workflows.
Examples
See the WorkflowFunctionApp in the example folder for more examples.
Preview: Activity history and durable entities
Use builder.AddDurableMediator(useExperimentalEntityExecution: true, typeof(Startup));
to enable entity execution
which allows for:
- Enable capturing request and response data to and from durable mediator invocations. This allows
IWorkflowManagement.GetWorkflowAsync
to output that data, making it possible to access the exact requests and responses after the workflow has completed.
The downside of this way feature is that every workflow will create a durable entity history record. This record
will be stored in the orchestration history storage (under @durablemediator@{instanceId}
) and needs to be cleared
using IDurableEntityClient.CleanEntityStorageAsync
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net7.0
- MediatR (>= 10.0.1)
- Microsoft.Azure.Functions.Worker.Extensions.DurableTask (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on DurableMediator.OutOfProcess:
Package | Downloads |
---|---|
DurableMediator.OutOfProcess.Testing
Durable Mediator is an extension to the Durable Task library which allows for running MediatR Requests as activities in orchestrations without any complex ceremony. This package allows for testing workflows using scenarios. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
3.1.0 | 128 | 4/16/2024 | |
3.1.0-preview-1 | 104 | 4/16/2024 | |
3.0.1-preview | 114 | 10/10/2023 | |
3.0.0-preview | 102 | 9/26/2023 | |
1.0.0 | 164 | 9/26/2023 |