![]() |
VOOZH | about |
dotnet add package Rebus.ServiceProvider --version 10.7.2
NuGet\Install-Package Rebus.ServiceProvider -Version 10.7.2
<PackageReference Include="Rebus.ServiceProvider" Version="10.7.2" />
<PackageVersion Include="Rebus.ServiceProvider" Version="10.7.2" />Directory.Packages.props
<PackageReference Include="Rebus.ServiceProvider" />Project file
paket add Rebus.ServiceProvider --version 10.7.2
#r "nuget: Rebus.ServiceProvider, 10.7.2"
#:package Rebus.ServiceProvider@10.7.2
#addin nuget:?package=Rebus.ServiceProvider&version=10.7.2Install as a Cake Addin
#tool nuget:?package=Rebus.ServiceProvider&version=10.7.2Install as a Cake Tool
Provides an Microsoft.Extensions.DependencyInjection-based container adapter for Rebus.
👁 alternate text is missing from this package README image
This container adapter is meant to be used with the generic host introduced with .NET Core 2.1, which has evolved into the ubiquitous hosting model for .NET.
When you configure your services, do this to invoke the Rebus configuration spell:
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, queueName))
);
and that is all there is to it! 😁 Rebus will use an IHostedService behind the covers to manage the Rebus instance, so it'll be started and stopped as the host conducts its background services.
If you need access to something that must be resolved from the container (e.g. configurations and stuff), there's an overload that passes the service provider to the configurer:
services.AddRebus(
(configure, provider) => {
var asb = provider.GetRequiredService<IOptions<AsbSettings>>();
var connectionString = asb.ConnectionString;
var queueName = asb.InputQueueName;
return configure
.Transport(t => t.UseAzureServiceBus(connectionString, queueName));
}
);
If you want to subscribe to stuff at startup, use the onCreated callback:
services.AddRebus(
(configure, provider) => {
var asb = provider.GetRequiredService<IOptions<AsbSettings>>();
var connectionString = asb.ConnectionString;
var queueName = asb.InputQueueName;
return configure
.Transport(t => t.UseAzureServiceBus(connectionString, queueName));
},
onCreated: async bus => {
await bus.Subscribe<FirstEvent>();
await bus.Subscribe<SecondEvent>();
}
);
and that's basically it.
If you're interested in hosting multiple Rebus instances inside a single process, please read on. 🙂
ℹ️ Please note that logging will be automatically configured - if possible, and if you haven't configured anything yourself.
As logging is integrated with the host, Rebus will simply direct all of its logging to loggers created using
the ILoggerFactory provided by the host, so if you want to log by some other means (e.g. with Serilog), you can
simply use the appropriate Serilog integration package and direct the host's logs to a Serilog sink.
It's still possible to e.g. append the usual .Logging(l => l.Serilog()) if you want to do that, but it's often easier
to just let Rebus use the host logging mechanism, and then configure logging in the host like you would anyway.
It can still be used outside of the generic host, but that will require usage to follow a pattern like this:
var services = new ServiceCollection();
services.AddRebus(...);
using var provider = services.BuildServiceProvider();
// THIS 👇 will start the bus(es)
provider.StartHostedServices();
⚠ With the generic host (which is what you're using, if you've created a console app, a background worker, or a web app), the configuration extensions
in this package rely on IHostedService and how the host uses these, and therefore the above call to StartHostedServices() shoule NOT be made.
ℹ With the generic host, there's two major modes of operation:
When sharing the host's container instance, starting one or more Rebus instances is as easy as
services.AddRebus(...);
as many times as you like.
⚠ But please note that there can be only ONE PRIMARY Rebus instance so you'll most likely follow a pattern like this:
// This one 👇 will be the primary bus instance
services.AddRebus(...);
services.AddRebus(isPrimaryBus: false, ...);
services.AddRebus(isPrimaryBus: false, ...);
if you want to add multiple Rebus instances.
When you add a Rebus instance with AddRebus, you can configure it the way you're used to via its RebusConfigurer and its extensions, so it could be something like
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, "my-queue-name"))
.Serializer(s => s.UseSystemTextJson())
);
for a single bus instance (which is also the default), or something like
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, "some-kind-of-processor"))
.Serializer(s => s.UseSystemTextJson())
);
services.AddRebus(
isPrimaryBus: false,
configure: configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, "some-kind-of-background-processor"))
.Serializer(s => s.UseSystemTextJson())
);
to add two bus instances. If you want to subscribe to something when starting up, there's an optional onCreated parameter that makes this possible, e.g. like this:
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, "my-queue-name"))
.Serializer(s => s.UseSystemTextJson()),
onCreated: async bus => {
await bus.Subscribe<SomethingInterestingHappened>();
await bus.Subscribe<AnotherInterestingThingHappened>();
}
);
The callback passed as onCreated will be executed when the bus is created and operational, but before it has begun consuming messages.
When you want to host additional Rebus instances in the same process, but you want an extra degree of separation from your host application (e.g. if you're following the
"modular monolith" approach), you can call the AddRebusService on the host builder for each independent background service you would like to add.
Since the background services are separate from the host, they each have their own container instance, and so you'll need to register whatever stuff they need to work.
In your startup code, you'll most likely find something that goes like this:
var builder = WebApplication.CreateBuilder(args);
// register stuff in builder.Services here
var app = builder.Build();
// maybe configure web app middlewares here
await app.RunAsync();
This builder has a Host property, which is where you will find the AddRebusService extension method:
builder.Host.AddRebusService(
services => (...)
);
It has a single callback, which is where you can configure the necessary services for the container instance dedicated to this background service. It requires that at
least ONE call be made to AddRebus like this:
builder.Host.AddRebusService(
services => services.AddRebus(...)
);
but otherwise it works like your normal service collection. This also means that it's totally fine to add multiple Rebus instance to it as well, if you like (but you'll probably want to mostly stay away from that to avoid giving your team mates a headache 🤯).
A typical configuraion could look like this (assuming that you're into the aesthetics of wrapping your registrations behind IServiceCollection extensions):
builder.Host.AddRebusService(
services => {
services.AddMyEfDatabaseContext();
services.AddMyRepositories();
services.AddMyApplicationServices();
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, "my-queue-name"))
);
services.AddRebusHandler<SomeMessageHandler>();
services.AddRebusHandler<AnotherMessageHandler>();
}
);
ℹ When using the separate background service approach described here, the container will forward calls for
Microsoft.Extensions.Hosting.IHostApplicationLifetimeMicrosoft.Extensions.Logging.ILoggerFactoryto the host's container, which essentially makes these things transparently available, as singletons, to the separate Rebus service.
If you forward requests for other singletons to the host's container you can add to the list of forwarded singleton types:
builder.Host.AddRebusService(
services => services.AddRebus(...),
typeof(IMyDateTimeProvider),
typeof(IMyImportantService),
... etc
);
When adding multiple bus instances to a single container instance, there's one big question that needs to be answered: Which bus instance will be returned if you resolve
IBus from it?
var bus = serviceProvider.GetRequiredService<IBus>();
// ???
or if you have an IBus injected:
public class SomethingPublisher
{
public SomethingPublisher(IBus bus) => ... //< ???
}
This where the concept of "default bus" is relevant.
If you need to be able to later resolve a specific bus instance from the service provider, you can register a bus with a key:
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, queueName)),
key: "my-favorite-bus"
);
Later, when your app is running, you will then be able to retrieve that specific bus instance via IBusRegistry like so:
var registry = provider.GetRequiredService<IBusRegistry>(); //< or have this injected
var bus = registry.GetBus("my-favorite-bus");
// voilá! 🎉
When you configure the bus, e.g. with
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, queueName)),
key: "my-favorite-bus"
);
and then the host starts up (or you call the StartHostedServices() extension method on the service provider), the bus will automatically be started (i.e.
it will start consuming messages).
You can delay the time of when message consumption is begun by setting startAutomatically: false in the call to AddRebus:
services.AddRebus(
configure => configure
.Transport(t => t.UseAzureServiceBus(connectionString, queueName)),
key: "my-favorite-bus",
startAutomatically: false //< the bus will be "started" with 0 workers, i.e. it will not consume anything
);
At a later time, when you think it's about time the bus gets to taste some sweet message goodness, you can start it via the registry:
var registry = provider.GetRequiredService<IBusRegistry>(); //< or have this injected
registry.StartBus("my-favorite-bus");
// voilá! 🎉
Since starting the bus this way requires that you retrieve it via the bus registry, it's a hard requirement that a KEY is provided when calling AddRebus.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Rebus.ServiceProvider:
| Package | Downloads |
|---|---|
|
Elsa.Core
Elsa is a set of workflow libraries and tools that enable lean and mean workflowing capabilities in any .NET Core application. This package contains the core of Elsa. Tip: reference the `Elsa` package instead of this one. |
|
|
Umbraco.Deploy.Cloud
Umbraco Deploy Cloud provides reliable deployment of schema, functionality, structure and content between Umbraco Cloud environments. This package can be used with Umbraco CMS version 9 and higher, for version 8 or below, please contact Umbraco support. |
|
|
EasyDesk.CleanArchitecture.Infrastructure
Utilities for the infrastructure layer of the clean architecture as seen by EasyDesk. |
|
|
Volo.Abp.EventBus.Rebus
Package Description |
|
|
ZhileTime.Hope.EventBus.Rebus
Package Description |
Showing the top 10 popular GitHub repositories that depend on Rebus.ServiceProvider:
| Repository | Stars |
|---|---|
|
abpframework/abp
Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
|
|
|
colinin/abp-next-admin
这是基于vue-vben-admin 模板适用于abp vNext的前端管理项目
|
|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
|
NexusForever/NexusForever
An emulator for the defunct MMORPG WildStar which supports build 16042 (Final Patch)
|
|
|
mastreeno/Merp
An event based Micro ERP
|
|
|
loyldg/mytelegram
Self-hosted Telegram server-side API implemented in C#
|
|
| opengram-server/opengram | |
|
stidsborg/Cleipnir.NET
Surviving crashes in plain C#-code
|
|
|
jxnkwlp/abp-elsa-module
Elsa abp module and workflow app
|
|
|
rebus-org/RebusSamples
Small sample projects
|
| Version | Downloads | Last Updated |
|---|---|---|
| 10.7.2 | 613,691 | 1/19/2026 |
| 10.7.1 | 79,034 | 1/5/2026 |
| 10.7.0 | 372,203 | 11/15/2025 |
| 10.6.0 | 71,509 | 10/22/2025 |
| 10.5.0 | 382,537 | 7/28/2025 |
| 10.4.0 | 2,155 | 7/28/2025 |
| 10.3.0 | 1,798,547 | 11/14/2024 |
| 10.2.0 | 337,678 | 9/9/2024 |
| 10.1.2 | 1,425,833 | 3/15/2024 |
| 10.1.1 | 81,575 | 2/24/2024 |
| 10.1.0 | 119,427 | 1/30/2024 |
| 10.0.0 | 805,855 | 11/15/2023 |
| 10.0.0-alpha04 | 4,481 | 6/24/2023 |
| 10.0.0-alpha03 | 1,705 | 6/14/2023 |
| 10.0.0-alpha02 | 1,439 | 6/14/2023 |
| 10.0.0-alpha01 | 5,364 | 3/27/2023 |
| 9.1.0 | 264,641 | 7/30/2023 |
| 9.0.0 | 360,104 | 3/27/2023 |
| 9.0.0-b02 | 2,714 | 3/15/2023 |
| 9.0.0-b01 | 1,469 | 3/15/2023 |