Skip to content

Commit

Permalink
chore(deps): remove guard.net references from the pumps abstractions …
Browse files Browse the repository at this point in the history
…project (#497)

* chore(deps): remove guard.net references from the pumps abstractions project

* chore(deps): remove guard.net references from the pumps abstractions project
  • Loading branch information
stijnmoreels authored Feb 28, 2025
1 parent d5881d3 commit 461ad77
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Threading.Tasks;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Arcus.Messaging.Pumps.Abstractions.Resiliency
Expand All @@ -21,8 +20,15 @@ public static async Task PauseMessageProcessingAsync(
this IMessagePumpCircuitBreaker circuitBreaker,
string jobId)
{
Guard.NotNull(circuitBreaker, nameof(circuitBreaker));
Guard.NotNullOrWhitespace(jobId, nameof(jobId));
if (circuitBreaker is null)
{
throw new ArgumentNullException(nameof(circuitBreaker));
}

if (string.IsNullOrWhiteSpace(jobId))
{
throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId));
}

await circuitBreaker.PauseMessageProcessingAsync(jobId, _ => { });
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Pumps.Abstractions;
using Arcus.Messaging.Pumps.Abstractions.Resiliency;
using GuardNet;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;

Expand All @@ -26,8 +25,15 @@ public static IServiceCollection AddMessagePump<TMessagePump>(
Func<IServiceProvider, TMessagePump> implementationFactory)
where TMessagePump : MessagePump
{
Guard.NotNull(services, nameof(services), "Requires an application services instance to register the custom message pump instance");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a factory implementation function to create the custom message pump instance");
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

if (implementationFactory is null)
{
throw new ArgumentNullException(nameof(implementationFactory));
}

services.TryAddSingleton<IMessagePumpLifetime, DefaultMessagePumpLifetime>();
services.TryAddSingleton<IMessagePumpCircuitBreaker>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using GuardNet;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
Expand All @@ -26,9 +25,7 @@ public class DefaultMessagePumpCircuitBreaker : IMessagePumpCircuitBreaker
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="serviceProvider"/> is <c>null</c>.</exception>
public DefaultMessagePumpCircuitBreaker(IServiceProvider serviceProvider, ILogger<DefaultMessagePumpCircuitBreaker> logger)
{
Guard.NotNull(serviceProvider, nameof(serviceProvider));

_serviceProvider = serviceProvider;
_serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
_logger = logger ?? NullLogger<DefaultMessagePumpCircuitBreaker>.Instance;
}

Expand All @@ -40,7 +37,10 @@ public DefaultMessagePumpCircuitBreaker(IServiceProvider serviceProvider, ILogge
/// <exception cref="ArgumentException">Thrown when the <paramref name="jobId"/> is blank.</exception>
public virtual Task PauseMessageProcessingAsync(string jobId, Action<MessagePumpCircuitBreakerOptions> configureOptions)
{
Guard.NotNullOrWhitespace(jobId, nameof(jobId));
if (string.IsNullOrWhiteSpace(jobId))
{
throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId));
}

MessagePump messagePump = GetRegisteredMessagePump(jobId);

Expand Down Expand Up @@ -69,7 +69,10 @@ public virtual Task PauseMessageProcessingAsync(string jobId, Action<MessagePump
/// <exception cref="ArgumentException">Thrown when the <paramref name="jobId"/> is blank.</exception>
public MessagePumpCircuitState GetCircuitBreakerState(string jobId)
{
Guard.NotNullOrWhitespace(jobId, nameof(jobId));
if (string.IsNullOrWhiteSpace(jobId))
{
throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId));
}

MessagePump messagePump = GetRegisteredMessagePump(jobId);
return messagePump.CircuitState;
Expand All @@ -82,7 +85,10 @@ public MessagePumpCircuitState GetCircuitBreakerState(string jobId)
/// <exception cref="InvalidOperationException">Thrown when not a single or more than one message pump could be found by the configured job ID.</exception>
protected MessagePump GetRegisteredMessagePump(string jobId)
{
Guard.NotNullOrWhitespace(jobId, nameof(jobId));
if (string.IsNullOrWhiteSpace(jobId))
{
throw new ArgumentException("Requires a non-blank unique job ID to identify he message pump", nameof(jobId));
}

MessagePump[] messagePumps =
_serviceProvider.GetServices<IHostedService>()
Expand Down

0 comments on commit 461ad77

Please sign in to comment.