VolocyNazad.Revit.MediatR
2025.0.9
dotnet add package VolocyNazad.Revit.MediatR --version 2025.0.9
NuGet\Install-Package VolocyNazad.Revit.MediatR -Version 2025.0.9
<PackageReference Include="VolocyNazad.Revit.MediatR" Version="2025.0.9" />
<PackageVersion Include="VolocyNazad.Revit.MediatR" Version="2025.0.9" />
<PackageReference Include="VolocyNazad.Revit.MediatR" />
paket add VolocyNazad.Revit.MediatR --version 2025.0.9
#r "nuget: VolocyNazad.Revit.MediatR, 2025.0.9"
#:package VolocyNazad.Revit.MediatR@2025.0.9
#addin nuget:?package=VolocyNazad.Revit.MediatR&version=2025.0.9
#tool nuget:?package=VolocyNazad.Revit.MediatR&version=2025.0.9
Revit.MediatR
MediatR pipeline service implementations for the Revit API.
Revit.MediatR is a set of pipeline-pattern service implementations for the Revit API with support
for DI containerization: commands and handlers that know how to marshal execution onto the Revit
API thread via ExternalEvent (VolocyNazad.Revit.Events)
and wrap it in a named transaction — without having to hand-write an IExternalEventHandler and
Transaction at every call site.
Installation
dotnet add package VolocyNazad.Revit.MediatR
The package version is tied to the Revit year: {RevitYear}.0.{patch} (e.g. 2025.0.7). It is
built for a specific Revit version depending on the selected build configuration — the same way as
Revit_All_Main_Versions_API_x64, which the project depends on.
DI Registration
using Revit.MediatR.DI;
services.AddMediatR();
This call registers VolocyNazad.Revit.Events (AddEvents) and VolocyNazad.Revit.Context
(AddRevitContext), then MediatR itself along with the handlers for the built-in lambda commands
and the Revit-specific pipeline behaviours (RevitTransactionBehaviour,
RevitExternalEventBehaviour), which automatically open a transaction and/or marshal execution
onto the Revit API thread.
Built-in Commands
| Command | Transaction | ExternalEvent |
|---|---|---|
LambdaTransactionCommand |
yes | no |
LambdaExternalEventCommand |
no | yes |
LambdaExternalEventTransactionCommand |
yes | yes |
All of them run in the context of a document (either explicitly passed or the active one from
IRevitContext) and return Response<bool> — a wrapper carrying the result, an error flag, a
message, and an exception.
Example: transaction on the active document
Response<bool> response = await mediator.Send(
new LambdaTransactionCommand(
document: null!, // ActiveDocument is taken from IRevitContext
transactionName: "Move wall",
@delegate: (doc, ct) =>
{
// changes to the model
return Task.FromResult(true);
}));
Example: execution via ExternalEvent (e.g. from a WPF modal window)
Response<bool> response = await mediator.Send(
new LambdaExternalEventTransactionCommand(
document: activeDocument,
transactionName: "Create level",
@delegate: (doc, ct) =>
{
// code that must run on the Revit API thread, inside a transaction
return Task.FromResult(true);
}));
Custom commands
You can create your own commands by inheriting from Revit.MediatR.Base.DocumentCommand and
implementing the marker interfaces Revit.MediatR.Abstractions.Models.ITransactionCommand and/or
IExternalEventCommand, as well as writing an IRequestHandler<TCommand, Response<bool>> for
them — the pipeline behaviours will pick them up automatically via these interfaces.
Supported Revit Versions
The package is built for every Revit version listed in the Configurations element of
src/Revit.MediatR/Revit.MediatR.csproj (2021.1.9, 2023.0.0, and 2025.0.0), targeting net48 or net8.0-windows
depending on the year — the switching and generation of define constants (IS2025, BEFORE2021,
AFTER2021, etc.) is handled by the shared MSBuild SDK
VolocyNazad.Revit.Sdk.
Development
dotnet build --configuration "Release_2025.0.0"— build for a specific Revit version.dotnet test --configuration "Release_2025.0.0"— unit tests (tests/Revit.MediatR.Tests). Tests that need real Revit-typed objects (Document) to work are markedSkip— theRevitAPI/RevitAPIUIassemblies are not loaded outside of the Revit process.- The package version is auto-versioned via MinVer from
git tags of the form
0.0.7; to release a new version, create a tag and push it:git tag 0.0.7 && git push origin main --follow-tags.
License
Development documentation
Contributing
CONTRIBUTING.md before submitting changes.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0-windows7.0 is compatible. net9.0-windows was computed. net10.0-windows was computed. |
-
net8.0-windows7.0
- MediatR (>= 14.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.11)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.11)
- Revit_All_Main_Versions_API_x64 (>= 2025.0.0)
- VolocyNazad.Revit.Context (>= 2025.0.9)
- VolocyNazad.Revit.Events (>= 2025.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.