Rebus.Microsoft.Extensions.Configuration 1.0.0

dotnet add package Rebus.Microsoft.Extensions.Configuration --version 1.0.0
NuGet\Install-Package Rebus.Microsoft.Extensions.Configuration -Version 1.0.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="Rebus.Microsoft.Extensions.Configuration" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rebus.Microsoft.Extensions.Configuration --version 1.0.0
#r "nuget: Rebus.Microsoft.Extensions.Configuration, 1.0.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.
// Install Rebus.Microsoft.Extensions.Configuration as a Cake Addin
#addin nuget:?package=Rebus.Microsoft.Extensions.Configuration&version=1.0.0

// Install Rebus.Microsoft.Extensions.Configuration as a Cake Tool
#tool nuget:?package=Rebus.Microsoft.Extensions.Configuration&version=1.0.0

Rebus.Microsoft.Extensions.Configuration

install from nuget

Provides a Microsoft Extensions Configuration integration for Rebus.

alternate text is missing from this package README image


In the newer incarnations of the .NET Framework, you're encouraged to configure your things via Microsoft.Extensions.Configuration.

While there's no doubt that the name is pretty silly, it's actually neatly designed, since it allows for picking up configuration from many different sources.

With Rebus.Microsoft.Extensions.Configuration you can have Rebus pick up your endpoint mappings from IConfiguration 😎

Let's say you have a configuration file, appsettings.json, which looks like this:

{
  "Mappings": {
    "TestApp.Messages": "testapp-queue",
    "AnotherApp.Messages": "anotherapp-queue"
  }
}

If you're using Microsoft's generic host, then you should include the Rebus.ServiceProvider package too, because then you can configure your bus instance simply like this:

var host = Host.CreateDefaultBuilder()
    .ConfigureServices((context, services) =>
    {
        services.AddRebus(
            configure => configure
                .Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "my-queue"))
                .Routing(r => r.TypeBased().AddMappingsFromConfiguration(context.Configuration, "Endpoints"))
        );
    })
    .Build();

host.Run();

If you are in place where the generic host is not available, you can still use the package in a slightly more manual way.

Start out by loading up your configuration file like this:

// build configuration
var configuration = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .Build();


If we then want Rebus to pick up the endpoint mapping from it, we can do it like this:

Configure.With(...)
    .Transport(...)
    .Routing(r => r.TypeBased().AddMappingsFromConfiguration(configuration, "Mappings"))
    .Start();

As you can see, we reference the Mappings object in the JSON by specifying it as an argument to AddMappingsFromConfiguration.

Since configuration can be loaded from many different sources, you just need to ensure that your mappings can be bound to a Dictionary<string, string>.

It even works with environment variables! You can make Microsoft.Extensions.Configuration load your environment variables like this:

var configuration = new ConfigurationBuilder()
    .AddEnvironmentVariables()
    .Build();

and then, if you configured the following variable:

RebusMappings:TestApp.Messages = some-queue

then it can be picked up like this:

Configure.With(...)
    .Transport(...)
    .Routing(r => r.TypeBased().AddMappingsFromConfiguration(configuration, "RebusMappings"))
    .Start();

which is super neat. 🙂

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.0.0 1,221 11/15/2023
1.0.0-alpha01 139 3/29/2023
0.0.4-a1 239 11/4/2020
0.0.3 40,479 11/4/2020
0.0.2 1,430 10/31/2019
0.0.1 453 10/31/2019