refactor(publisher)!: simplify AddMessagingServicePublisher registration
Replace the MessagingServicePublisherConfiguration builder with plain overloads that accept either a configuration delegate or IConfiguration. Update EmailSender and the publisher integration test to the new API, and mark the static EmailSender obsolete ahead of the new client. BREAKING CHANGE: AddMessagingServicePublisher no longer accepts a builder configuration delegate.
This commit is contained in:
@@ -13,14 +13,17 @@ namespace DigitalData.MessagingService.Client;
|
||||
/// <remarks>
|
||||
/// This class manages its own internal <see cref="IServiceProvider"/> using a
|
||||
/// <see cref="Lazy{T}"/> pattern so the DI container is only built once,
|
||||
/// on the first call to <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/>.
|
||||
/// on the first call to <see cref="ConnectRabbitMq(Action{RabbitMqConnectionConfiguration}, OnReconnect)"/>.
|
||||
/// </remarks>
|
||||
#if NET
|
||||
[Obsolete("Use MessagingServiceClient with dependency injection instead.")]
|
||||
#endif
|
||||
public static class EmailSender
|
||||
{
|
||||
/// <summary>
|
||||
/// Internal event used to accumulate service registrations before the
|
||||
/// <see cref="IServiceProvider"/> is built. Handlers are added by
|
||||
/// <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/> and invoked exactly once during
|
||||
/// <see cref="ConnectRabbitMq(Action{RabbitMqConnectionConfiguration}, OnReconnect)"/> and invoked exactly once during
|
||||
/// lazy initialization.
|
||||
/// </summary>
|
||||
private static event Action<IServiceCollection> ConfigureServices = delegate { };
|
||||
@@ -43,7 +46,7 @@ public static class EmailSender
|
||||
/// and the internal <see cref="IServiceProvider"/> has been initialized.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <see langword="true"/> if <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/> has been called
|
||||
/// <see langword="true"/> if <see cref="ConnectRabbitMq(Action{RabbitMqConnectionConfiguration}, OnReconnect)"/> has been called
|
||||
/// and the provider is built; otherwise <see langword="false"/>.
|
||||
/// </value>
|
||||
public static bool IsConnected => LazyProvider.IsValueCreated;
|
||||
@@ -53,7 +56,7 @@ public static class EmailSender
|
||||
/// the internal dependency injection container.
|
||||
/// </summary>
|
||||
/// <param name="configure">
|
||||
/// A delegate used to configure the <see cref="RabbitMqConfiguration"/>,
|
||||
/// A delegate used to configure the <see cref="RabbitMqConnectionConfiguration"/>,
|
||||
/// such as host, port, credentials, and exchange settings.
|
||||
/// </param>
|
||||
/// <param name="onReconnect">
|
||||
@@ -64,12 +67,12 @@ public static class EmailSender
|
||||
/// Thrown when the service is already connected and
|
||||
/// <paramref name="onReconnect"/> is <see cref="OnReconnect.ThrowException"/>.
|
||||
/// </exception>
|
||||
public static void ConnectRabbitMq(Action<RabbitMqConfiguration> configure, OnReconnect onReconnect = OnReconnect.ThrowException)
|
||||
public static void ConnectRabbitMq(Action<RabbitMqConnectionConfiguration> configure, OnReconnect onReconnect = OnReconnect.ThrowException)
|
||||
{
|
||||
if(IsConnected && onReconnect == OnReconnect.ThrowException)
|
||||
throw new InvalidOperationException("Messaging service is already connected.");
|
||||
|
||||
ConfigureServices += services => services.AddMessagingServicePublisher(cfg => cfg.AddRabbitMqConnectionFactory(configure));
|
||||
ConfigureServices += services => services.AddMessagingServicePublisher(configure);
|
||||
_ = LazyProvider.Value; // Force initialization
|
||||
}
|
||||
|
||||
@@ -111,7 +114,7 @@ public static class EmailSender
|
||||
/// </summary>
|
||||
/// <param name="email">The outgoing email data to enqueue.</param>
|
||||
/// <exception cref="InvalidOperationException">
|
||||
/// Thrown when <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/> has not been called prior to sending.
|
||||
/// Thrown when <see cref="ConnectRabbitMq(Action{RabbitMqConnectionConfiguration}, OnReconnect)"/> has not been called prior to sending.
|
||||
/// </exception>
|
||||
/// <remarks>
|
||||
/// This method maps <see cref="EmailContext"/> to <see cref="SendingEmailEvent"/>,
|
||||
|
||||
Reference in New Issue
Block a user