diff --git a/src/HotChocolate/Core/src/Subscriptions.RabbitMQ/DependencyInjection/RabbitMQPubSubExtensions.cs b/src/HotChocolate/Core/src/Subscriptions.RabbitMQ/DependencyInjection/RabbitMQPubSubExtensions.cs index 66497aea3c2..3c8d2636c56 100644 --- a/src/HotChocolate/Core/src/Subscriptions.RabbitMQ/DependencyInjection/RabbitMQPubSubExtensions.cs +++ b/src/HotChocolate/Core/src/Subscriptions.RabbitMQ/DependencyInjection/RabbitMQPubSubExtensions.cs @@ -44,25 +44,49 @@ public static IRequestExecutorBuilder AddRabbitMQSubscriptions( throw new ArgumentNullException(nameof(builder)); } - builder - .AddSubscriptionDiagnostics() - .Services - .AddRabbitMQSubscriptions(connectionFactory, options); + builder.Services + .AddRabbitMQSubscriptionPublisher(connectionFactory, options) + .TryAddSingleton(sp => sp.GetRequiredService()); return builder; } - private static void AddRabbitMQSubscriptions( + /// + /// Registers the RabbitMQ subscription provider for use in publisher scenarios where the graphql server is + /// not running, but you still want to publish events via RabbitMQ for another process to receive. + /// + /// + /// The service collecion builder. + /// + /// + /// The RabbitMQ connection factory. This parameter is optional; the default value is null. + /// The following properties will be overriden with true to make the connection recoverable. + /// - AutomaticRecoveryEnabled + /// - DispatchConsumersAsync + /// + /// + /// The subscription provider options. This parameter is optional; the default value is null. + /// + /// + /// Returns the GraphQL configuration builder for configuration chaining. + /// + /// + /// is null. + /// + public static IServiceCollection AddRabbitMQSubscriptionPublisher( this IServiceCollection services, ConnectionFactory? connectionFactory = null, SubscriptionOptions? options = null) { + services.AddSubscriptionDiagnostics(); + services.TryAddSingleton(connectionFactory ?? new ConnectionFactory()); services.TryAddSingleton(); services.TryAddSingleton(options ?? new SubscriptionOptions()); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(sp => sp.GetRequiredService()); - services.TryAddSingleton(sp => sp.GetRequiredService()); + + return services; } }