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
                    
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="VolocyNazad.Revit.MediatR" Version="2025.0.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="VolocyNazad.Revit.MediatR" Version="2025.0.9" />
                    
Directory.Packages.props
<PackageReference Include="VolocyNazad.Revit.MediatR" />
                    
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 VolocyNazad.Revit.MediatR --version 2025.0.9
                    
#r "nuget: VolocyNazad.Revit.MediatR, 2025.0.9"
                    
#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 VolocyNazad.Revit.MediatR@2025.0.9
                    
#: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=VolocyNazad.Revit.MediatR&version=2025.0.9
                    
Install as a Cake Addin
#tool nuget:?package=VolocyNazad.Revit.MediatR&version=2025.0.9
                    
Install as a Cake Tool

Revit.MediatR

Revit 2021.1.9, 2023, 2025 License: MIT VolocyNazad

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 marked Skip — the RevitAPI/RevitAPIUI assemblies 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

MIT

Development documentation

Contributing

CONTRIBUTING.md before submitting changes.

Product Compatible and additional computed target framework versions.
.NET net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows 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
2025.0.9 87 9/21/2026
2025.0.8 102 9/6/2026
2025.0.7 112 8/13/2026
2025.0.6 176 6/19/2026
2023.0.9 85 9/21/2026
2023.0.8 100 9/6/2026
2023.0.7 91 8/13/2026
2023.0.6 126 6/19/2026
2021.0.9 81 9/21/2026
2021.0.8 94 9/6/2026
2021.0.7 117 8/13/2026
2021.0.6 132 6/19/2026