Cogito.MassTransit.DependencyInjection 3.1.0

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

Cogito.MassTransit.DependencyInjection

Registers MassTransit consumers, sagas and activities from attributes on the types themselves, onto any bus.

Why

AddMassTransit wants every consumer and saga listed inside its configuration lambda, so the place a bus is set up has to know every type that runs on it. With attributes, each type says which bus it runs on and how its endpoint is named, and a host only adds the assemblies it wants. The types are registered through MassTransit's own registration API, so they behave exactly as if they had been added in the lambda.

Install

dotnet add package Cogito.MassTransit.DependencyInjection

Use

Apply the attributes:

[AddConsumer(EndpointName = "orders")]
public class SubmitOrderConsumer : IConsumer<SubmitOrder> { ... }

[AddSagaStateMachine(EndpointName = "order-state")]
[InMemorySagaRepository]
public class OrderStateMachine : MassTransitStateMachine<OrderState> { ... }

Then add the bus, and the assemblies whose types to register, with AddFromAttributes from Cogito.DependencyInjection:

services.AddMassTransit(x => x.UsingRabbitMq((context, cfg) => cfg.ConfigureEndpoints(context)));
services.AddFromAttributes(typeof(Program).Assembly);

The types join the endpoints ConfigureEndpoints creates. It does not matter whether AddFromAttributes comes before or after AddMassTransit, except for sagas without a repository attribute (below).

The registrations are made on the IServiceCollection, so an Autofac host that populates from it gets them too.

Attributes

Attribute Registers
[AddConsumer] A consumer.
[AddSagaStateMachine] A saga state machine.
[AddSaga] A saga class.
[AddActivity] A routing slip activity, which executes and compensates.
[AddExecuteActivity] An execute-only routing slip activity.

Each takes:

  • Bus, the bus to register onto. It is IBus unless set to the interface given to AddMassTransit<TBus>. Apply the attribute more than once to register a type onto more than one bus.
  • Definition, a MassTransit definition for the type, such as a ConsumerDefinition<T>.
  • ExcludeFromConfigureEndpoints, which leaves the type off the endpoints ConfigureEndpoints creates.

All but [AddActivity] also take the endpoint's EndpointName, PrefetchCount, ConcurrentMessageLimit, IsTemporary, InstanceId and ConfigureConsumeTopology. [AddActivity] takes ExecuteEndpointName and CompensateEndpointName; configure anything more about its endpoints with a definition. Endpoint properties that are not set fall to the definition, or to the bus's endpoint name formatter.

public interface IBackOfficeBus : IBus { }

[AddConsumer(Bus = typeof(IBackOfficeBus), EndpointName = "reports", ConcurrentMessageLimit = 4)]
public class ReportConsumer : IConsumer<RunReport> { ... }

Saga repositories

A saga needs a repository. Apply a repository attribute to the saga, or to its state machine:

Without one, the saga takes the repository provider set on the bus, such as SetInMemorySagaRepositoryProvider(), but only if AddFromAttributes comes before AddMassTransit: MassTransit assigns the provider's repositories as AddMassTransit completes. A saga registered from attributes that has no repository fails the host's startup, rather than its first message.

License

MIT.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Cogito.MassTransit.DependencyInjection:

Package Downloads
Cogito.MassTransit.EntityFrameworkCore.DependencyInjection

Keeps MassTransit saga instances in Entity Framework Core, registered from an attribute on the saga.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 40 10/15/2026