Dosaic.Plugins.Messaging.Abstractions 1.2.9

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

Dosaic.Plugins.Messaging.Abstractions

Core abstractions for Dosaic messaging plugins. This package defines the contracts that messaging implementations (such as Dosaic.Plugins.Messaging.MassTransit) must fulfill, and that application code depends on to send, schedule, and consume messages in a transport-agnostic way.

Installation

dotnet add package Dosaic.Plugins.Messaging.Abstractions

Interfaces

IMessage

Marker interface that every message contract must implement. It carries no members — its only purpose is to allow the framework and transport implementations to identify and route message types safely.

public interface IMessage;

IMessageBus

The primary entry point for publishing messages. Inject IMessageBus wherever you need to send or schedule messages. The concrete implementation is registered by the chosen messaging plugin (e.g. MessageBusPlugin from Dosaic.Plugins.Messaging.MassTransit).

public interface IMessageBus
{
    // Send a strongly-typed message immediately
    Task SendAsync<TMessage>(TMessage message,
        IDictionary<string, string> headers = null,
        CancellationToken cancellationToken = default)
        where TMessage : IMessage;

    // Send a message when the type is only known at runtime
    Task SendAsync(Type messageType, object message,
        IDictionary<string, string> headers = null,
        CancellationToken cancellationToken = default);

    // Schedule a strongly-typed message after a relative delay
    Task ScheduleAsync<TMessage>(TMessage message, TimeSpan duration,
        IDictionary<string, string> headers = null,
        CancellationToken cancellationToken = default)
        where TMessage : IMessage;

    // Schedule a strongly-typed message at an absolute point in time
    Task ScheduleAsync<TMessage>(TMessage message, DateTime scheduledDate,
        IDictionary<string, string> headers = null,
        CancellationToken cancellationToken = default)
        where TMessage : IMessage;

    // Schedule an untyped message after a relative delay
    Task ScheduleAsync(Type messageType, object message, TimeSpan duration,
        IDictionary<string, string> headers = null,
        CancellationToken cancellationToken = default);

    // Schedule an untyped message at an absolute point in time
    Task ScheduleAsync(Type messageType, object message, DateTime scheduledTime,
        IDictionary<string, string> headers = null,
        CancellationToken cancellationToken = default);
}

Notes:

  • SendAsync and ScheduleAsync are no-ops when no consumer is registered for the given message type — messages are silently dropped rather than raising an error.
  • ScheduleAsync requires a configured message scheduler. If the underlying transport has no scheduler configured, an InvalidOperationException is thrown.
  • Optional headers are forwarded as transport-level headers on every send/schedule call.

IMessageConsumer<TMessage>

Implement this interface to handle incoming messages of a specific type. Multiple consumers for the same message type are supported — all registered consumers are invoked in parallel when a message arrives.

public interface IMessageConsumer<in TMessage>
    where TMessage : IMessage
{
    Task ProcessAsync(TMessage message, CancellationToken cancellationToken = default);
}

The messaging plugin discovers all IMessageConsumer<TMessage> implementations at startup and registers them automatically. No additional registration is required.


IMessageValidator

Internal contract used by messaging implementations to check whether a registered consumer exists for a given message type before attempting to route a message. Application code does not normally need to interact with this interface directly.

public interface IMessageValidator
{
    bool HasConsumers(Type t);
}

Usage

Defining a message

using Dosaic.Plugins.Messaging.Abstractions;

namespace MyService.Messages;

public record OrderPlaced(Guid OrderId, decimal Total) : IMessage;

Implementing a consumer

using Dosaic.Plugins.Messaging.Abstractions;

namespace MyService.Consumers;

public class OrderPlacedConsumer : IMessageConsumer<OrderPlaced>
{
    public async Task ProcessAsync(OrderPlaced message, CancellationToken cancellationToken = default)
    {
        // Handle the message
        Console.WriteLine($"Order {message.OrderId} placed for {message.Total:C}");
    }
}

The consumer is automatically discovered and registered by the messaging plugin — no explicit services.Add* call is needed.

Sending a message

Inject IMessageBus and call SendAsync:

using Dosaic.Plugins.Messaging.Abstractions;

namespace MyService.Services;

public class OrderService(IMessageBus messageBus)
{
    public async Task PlaceOrder(Guid orderId, decimal total, CancellationToken ct)
    {
        // ... business logic ...

        await messageBus.SendAsync(new OrderPlaced(orderId, total), cancellationToken: ct);
    }
}

Scheduling a message

Use ScheduleAsync with either a TimeSpan (relative) or a DateTime (absolute):

// Send after 30 minutes
await messageBus.ScheduleAsync(new OrderPlaced(orderId, total), TimeSpan.FromMinutes(30), cancellationToken: ct);

// Send at a specific UTC time
await messageBus.ScheduleAsync(new OrderPlaced(orderId, total), DateTime.UtcNow.AddHours(2), cancellationToken: ct);

Sending with custom headers

var headers = new Dictionary<string, string>
{
    ["x-correlation-id"] = correlationId.ToString(),
    ["x-tenant-id"] = tenantId
};

await messageBus.SendAsync(new OrderPlaced(orderId, total), headers, ct);
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Dosaic.Plugins.Messaging.Abstractions:

Package Downloads
Dosaic.Plugins.Messaging.MassTransit

A plugin-first dotnet framework for rapidly building anything hosted in the web.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.9 0 3/13/2026
1.2.8 88 3/9/2026
1.2.7 86 3/4/2026
1.2.6 114 2/19/2026
1.2.5 92 2/17/2026
1.2.4 127 2/13/2026
1.2.3 116 1/27/2026
1.2.2 314 12/16/2025
1.2.1 281 12/16/2025
1.2.0 443 12/11/2025
1.1.21 463 12/10/2025
1.1.20 444 11/18/2025
1.1.19 321 11/11/2025
1.1.18 215 10/14/2025
1.1.17 214 10/1/2025
1.1.16 229 9/25/2025
1.1.15 214 9/24/2025
1.1.14 217 9/24/2025
1.1.13 224 9/24/2025
1.1.12 355 9/16/2025
Loading failed