### Quickstart - Configuration with Service Provider Access Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md This code snippet demonstrates how to configure Rebus when access to the service provider is needed, for example, to retrieve configuration options. ```csharp services.AddRebus( (configure, provider) => { var asb = provider.GetRequiredService> (); var connectionString = asb.ConnectionString; var queueName = asb.InputQueueName; return configure .Transport(t => t.UseAzureServiceBus(connectionString, queueName)); } ); ``` -------------------------------- ### Manually starting the bus Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Example of manually starting a Rebus bus using the IBusRegistry. ```csharp var registry = provider.GetRequiredService(); //< or have this injected registry.StartBus("my-favorite-bus"); // voilá! 🎉 ``` -------------------------------- ### Configuring Rebus with delayed start Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Example of configuring Rebus to not start automatically, allowing for manual start later. ```csharp 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 ); ``` -------------------------------- ### Hosting outside of the generic host Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Example of how to use Rebus.ServiceProvider outside of the generic host, including building the service provider and starting hosted services. ```csharp var services = new ServiceCollection(); services.AddRebus(...); using var provider = services.BuildServiceProvider(); // THIS 👇 will start the bus(es) provider.StartHostedServices(); ``` -------------------------------- ### Quickstart - Configuration with Subscription at Startup Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md This code snippet shows how to configure Rebus and subscribe to events at startup using the 'onCreated' callback. ```csharp services.AddRebus( (configure, provider) => { var asb = provider.GetRequiredService> (); var connectionString = asb.ConnectionString; var queueName = asb.InputQueueName; return configure .Transport(t => t.UseAzureServiceBus(connectionString, queueName)); }, onCreated: async bus => { await bus.Subscribe(); await bus.Subscribe(); } ); ``` -------------------------------- ### Basic WebApplication setup Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md A standard ASP.NET Core WebApplication setup, illustrating where Rebus service registration can occur. ```csharp var builder = WebApplication.CreateBuilder(args); // register stuff in builder.Services here var app = builder.Build(); // maybe configure web app middlewares here await app.RunAsync(); ``` -------------------------------- ### Example Git Commit Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/CONTRIBUTING.md An example of how to make a commit with a message. ```git git commit -am"bam!!!11" ``` -------------------------------- ### Quickstart - Basic Configuration Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md This code snippet shows the basic configuration for Rebus using Azure Service Bus transport within a .NET Core 2.1+ generic host. ```csharp services.AddRebus( configure => configure .Transport(t => t.UseAzureServiceBus(connectionString, queueName)) ); ``` -------------------------------- ### Registering a Rebus instance with a key Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Example of how to register a specific Rebus bus instance with a unique key for later retrieval. ```csharp services.AddRebus( configure => configure .Transport(t => t.UseAzureServiceBus(connectionString, queueName)), key: "my-favorite-bus" ); ``` -------------------------------- ### Configuring Rebus with Azure Service Bus Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Example of configuring Rebus with Azure Service Bus transport. ```csharp services.AddRebus( configure => configure .Transport(t => t.UseAzureServiceBus(connectionString, queueName)), key: "my-favorite-bus" ); ``` -------------------------------- ### Typical Rebus service configuration Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md An example of a comprehensive configuration for a Rebus background service, including database context, repositories, application services, Rebus transport, and handlers. ```csharp builder.Host.AddRebusService( services => { services.AddMyEfDatabaseContext(); services.AddMyRepositories(); services.AddMyApplicationServices(); services.AddRebus( configure => configure .Transport(t => t.UseAzureServiceBus(connectionString, "my-queue-name")) ); services.AddRebusHandler(); services.AddRebusHandler(); } ); ``` -------------------------------- ### Retrieving a specific bus instance using IBusRegistry Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Demonstrates how to get a specific Rebus bus instance from the service provider using its registered key via `IBusRegistry`. ```csharp var registry = provider.GetRequiredService(); //< or have this injected var bus = registry.GetBus("my-favorite-bus"); ``` -------------------------------- ### Basic Rebus instance registration Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Shows the simplest way to add a Rebus instance to the service collection. ```csharp services.AddRebus(...); ``` -------------------------------- ### Configuring Rebus with an onCreated callback for subscriptions Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Demonstrates how to use the `onCreated` parameter to subscribe to events when a Rebus bus is initialized. ```csharp services.AddRebus( configure => configure .Transport(t => t.UseAzureServiceBus(connectionString, "my-queue-name")) .Serializer(s => s.UseSystemTextJson()), onCreated: async bus => { await bus.Subscribe(); await bus.Subscribe(); } ); ``` -------------------------------- ### Configuring a single Rebus instance with transport and serializer Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Demonstrates configuring a single Rebus instance with Azure Service Bus transport and System.Text.Json serializer. ```csharp services.AddRebus( configure => configure .Transport(t => t.UseAzureServiceBus(connectionString, "my-queue-name")) .Serializer(s => s.UseSystemTextJson()) ); ``` -------------------------------- ### Adding a Rebus service to the host builder Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Demonstrates how to use the `AddRebusService` extension method on the host builder to configure an independent background Rebus service. ```csharp builder.Host.AddRebusService( services => (...) ); ``` -------------------------------- ### Forwarding singleton types to the host container Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Shows how to explicitly forward specific singleton types from the host's container to the separate Rebus service container. ```csharp builder.Host.AddRebusService( services => services.AddRebus(...), typeof(IMyDateTimeProvider), typeof(IMyImportantService), ... etc ); ``` -------------------------------- ### Registering multiple Rebus instances with a primary bus Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Illustrates how to register multiple Rebus instances, designating one as the primary bus. ```csharp // This one \n will be the primary bus instance services.AddRebus(...); services.AddRebus(isPrimaryBus: false, ...); services.AddRebus(isPrimaryBus: false, ...); ``` -------------------------------- ### Configuring two Rebus instances with different queues Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md Shows how to configure two Rebus instances, each with a different Azure Service Bus queue name. ```csharp 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()) ); ``` -------------------------------- ### Minimum Rebus service registration Source: https://github.com/rebus-org/rebus.serviceprovider/blob/master/README.md The essential configuration for `AddRebusService`, requiring at least one call to `AddRebus`. ```csharp builder.Host.AddRebusService( services => services.AddRebus(...) ); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.