Skip to main content

On This Page

Beyond MediatR: Scaling .NET Messaging with ConduitR Design-Time Intelligence

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

ConduitR: Solving the “Black Box” of .NET Messaging

ConduitR is an open-source messaging framework designed to replace traditional mediator patterns with high-performance, transparent execution paths. The system utilizes a Roslyn Analyzer to identify orphaned requests and registration errors during development rather than at runtime.

Why This Matters

Traditional mediator implementations often act as a black box, obscuring request flows and leading to documentation debt where diagrams drift from the actual code. By integrating design-time intelligence and automated CLI documentation, ConduitR bridges the gap between architectural models and technical reality, ensuring performance remains high through zero-allocation ValueTask paths and cached pipelines.

Key Insights

  • The ConduitR Roslyn Analyzer flags orphaned IRequest definitions and duplicate handler registrations directly in the IDE to prevent runtime failures.
  • ConduitR CLI generates live sequence diagrams via Mermaid.js or PlantUML by scanning compiled assemblies to ensure documentation matches code.
  • Execution pipelines are cached per request type to bypass reflection-heavy overhead, optimizing performance for hot paths in high-scale APIs.
  • Native OpenTelemetry integration uses a built-in ActivitySource to automatically generate spans for distributed tracing in Jaeger or Application Insights.
  • First-party support for Polly allows for the seamless addition of retries and circuit breakers via simple behavior configurations.

Working Examples

Definition of a request and its handler using ValueTask for optimized performance.

public record UpdateProfile(Guid UserId, string Bio) : IRequest<bool>;

public class UpdateProfileHandler : IRequestHandler<UpdateProfile, bool>
{
    public async ValueTask<bool> Handle(UpdateProfile request, CancellationToken ct)
    {
        // High-performance logic with zero allocations for synchronous paths
        return true;
    }
}

CLI command to generate a live sequence diagram from a compiled assembly.

conduitr doc --assembly ./bin/Debug/net9.0/MyApi.dll --output ./docs/architecture.md

Configuring ConduitR with native OpenTelemetry and validation support.

services.AddConduit(options =>
{
    options.RegisterServicesFromAssembly(typeof(Program).Assembly);
    options.AddOpenTelemetry(); // Instant tracing
    options.AddConduitValidation(); // Automatic FluentValidation support
});

Practical Applications

  • Use Case: High-scale APIs on Azure Container Apps leveraging ConduitR’s cached pipelines to minimize latency in request processing. Pitfall: Relying on reflection-heavy mediators in performance-critical paths can lead to significant memory allocations.
  • Use Case: Maintaining live architectural documentation in enterprise systems by integrating the ConduitR CLI into CI/CD pipelines. Pitfall: Manually updated sequence diagrams frequently become obsolete, leading to architectural drift and onboarding friction.

References:

Continue reading

Next article

Hardening Linux Operations: Bash Security Patterns for Script Organization

Related Content