Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove guard.net references from abstractions #462

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Guard.NET" Version="3.0.0" />
<PackageReference Include="Arcus.Observability.Telemetry.Serilog.Enrichers" Version="[3.0.0,4.0.0)" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ public static class IDictionaryExtensions
public static (string transactionId, string operationParentId) GetTraceParent(
this IReadOnlyDictionary<string, object> applicationProperties)
{
Guard.NotNull(applicationProperties, nameof(applicationProperties), "Requires a set of application properties to retrieve the 'traceparent' property");
if (applicationProperties is null)
{
throw new ArgumentNullException(nameof(applicationProperties));
}

return GetTraceParent((IDictionary<string, object>) applicationProperties);
}

Expand All @@ -30,7 +34,10 @@ public static (string transactionId, string operationParentId) GetTraceParent(
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="applicationProperties"/> is <c>null</c>.</exception>
public static (string transactionId, string operationParentId) GetTraceParent(this IDictionary<string, object> applicationProperties)
{
Guard.NotNull(applicationProperties, nameof(applicationProperties), "Requires a set of application properties to retrieve the 'traceparent' property");
if (applicationProperties is null)
{
throw new ArgumentNullException(nameof(applicationProperties));
}

if (applicationProperties.TryGetValue("Diagnostic-Id", out object value)
&& value != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Arcus.Messaging.Abstractions;
using Arcus.Messaging.Abstractions.MessageHandling;
using Arcus.Observability.Correlation;
using GuardNet;
using Microsoft.Extensions.Logging;

// ReSharper disable once CheckNamespace
Expand All @@ -21,8 +20,6 @@ public static class IServiceCollectionExtensions
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="services"/> is <c>null</c>.</exception>
public static MessageHandlerCollection AddMessageRouting(this IServiceCollection services)
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message routing");

MessageHandlerCollection collection = AddMessageRouting(services, configureOptions: null);
return collection;
}
Expand All @@ -35,8 +32,6 @@ public static MessageHandlerCollection AddMessageRouting(this IServiceCollection
/// <exception cref="ArgumentNullException">Thrown when the <paramref name="services"/> is <c>null</c>.</exception>
public static MessageHandlerCollection AddMessageRouting(this IServiceCollection services, Action<MessageRouterOptions> configureOptions)
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message routing");

MessageHandlerCollection collection = AddMessageRouting(services, serviceProvider =>
{
var options = new MessageRouterOptions();
Expand All @@ -61,8 +56,15 @@ public static MessageHandlerCollection AddMessageRouting<TMessageRouter>(
Func<IServiceProvider, TMessageRouter> implementationFactory)
where TMessageRouter : IMessageRouter
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message routing");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message router");
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

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

services.AddApplicationInsightsTelemetryWorkerService();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Abstractions;
using Arcus.Messaging.Abstractions.MessageHandling;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -27,10 +26,7 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessageHandler : class, IMessageHandler<TMessage, MessageContext>
where TMessage : class
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");

return services.WithMessageHandler<TMessageHandler, TMessage, MessageContext>(messageBodyFilter);
return WithMessageHandler<TMessageHandler, TMessage, MessageContext>(services, messageBodyFilter);
}

/// <summary>
Expand All @@ -50,11 +46,8 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessage : class
where TMessageContext : MessageContext
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");

return services.WithMessageHandler<TMessageHandler, TMessage, TMessageContext>(
messageBodyFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
return WithMessageHandler<TMessageHandler, TMessage, TMessageContext>(
services, messageBodyFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
}

/// <summary>
Expand All @@ -74,11 +67,7 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessageHandler : class, IMessageHandler<TMessage, MessageContext>
where TMessage : class
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent services");

return services.WithMessageHandler<TMessageHandler, TMessage, MessageContext>(messageBodyFilter, implementationFactory);
return WithMessageHandler<TMessageHandler, TMessage, MessageContext>(services, messageBodyFilter, implementationFactory);
}

/// <summary>
Expand All @@ -100,9 +89,20 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessage : class
where TMessageContext : MessageContext
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent services");
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

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

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

services.AddMessageHandler(implementationFactory, messageBodyFilter: messageBodyFilter);
return services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessageHandler : class, IMessageHandler<TMessage, MessageContext>
where TMessage : class
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent services");

return services.WithMessageHandler<TMessageHandler, TMessage, MessageContext>(messageContextFilter, messageBodyFilter, implementationFactory);
return WithMessageHandler<TMessageHandler, TMessage, MessageContext>(services, messageContextFilter, messageBodyFilter, implementationFactory);
}

/// <summary>
Expand All @@ -56,10 +51,6 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessageHandler : class, IMessageHandler<TMessage, MessageContext>
where TMessage : class
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");

return WithMessageHandler<TMessageHandler, TMessage, MessageContext>(services, messageContextFilter, messageBodyFilter);
}

Expand All @@ -82,12 +73,8 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessage : class
where TMessageContext : MessageContext
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");

return services.WithMessageHandler(
messageContextFilter, messageBodyFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
return WithMessageHandler(
services, messageContextFilter, messageBodyFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
}

/// <summary>
Expand All @@ -111,10 +98,25 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessage : class
where TMessageContext : MessageContext
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(messageBodyFilter, nameof(messageBodyFilter), "Requires a filter to restrict the message processing based on the incoming message body");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent services");
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

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

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

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

services.AddMessageHandler(implementationFactory, messageBodyFilter, messageContextFilter);
return services;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using Arcus.Messaging.Abstractions;
using Arcus.Messaging.Abstractions.MessageHandling;
using GuardNet;

// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -27,10 +26,7 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessageHandler : class, IMessageHandler<TMessage, MessageContext>
where TMessage : class
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");

return services.WithMessageHandler<TMessageHandler, TMessage, MessageContext>(messageContextFilter);
return WithMessageHandler<TMessageHandler, TMessage, MessageContext>(services, messageContextFilter);
}

/// <summary>
Expand All @@ -50,11 +46,7 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessageHandler : class, IMessageHandler<TMessage, MessageContext>
where TMessage : class
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent services");

return services.WithMessageHandler<TMessageHandler, TMessage, MessageContext>(messageContextFilter, implementationFactory);
return WithMessageHandler<TMessageHandler, TMessage, MessageContext>(services, messageContextFilter, implementationFactory);
}

/// <summary>
Expand All @@ -74,11 +66,8 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessage : class
where TMessageContext : MessageContext
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");

return services.WithMessageHandler<TMessageHandler, TMessage, TMessageContext>(
messageContextFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
return WithMessageHandler<TMessageHandler, TMessage, TMessageContext>(
services, messageContextFilter, serviceProvider => ActivatorUtilities.CreateInstance<TMessageHandler>(serviceProvider));
}

/// <summary>
Expand All @@ -100,9 +89,20 @@ public static MessageHandlerCollection WithMessageHandler<TMessageHandler, TMess
where TMessage : class
where TMessageContext : MessageContext
{
Guard.NotNull(services, nameof(services), "Requires a set of services to add the message handler");
Guard.NotNull(messageContextFilter, nameof(messageContextFilter), "Requires a filter to restrict the message processing within a certain message context");
Guard.NotNull(implementationFactory, nameof(implementationFactory), "Requires a function to create the message handler with dependent services");
if (services is null)
{
throw new ArgumentNullException(nameof(services));
}

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

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

services.AddMessageHandler(implementationFactory, messageContextFilter: messageContextFilter);
return services;
Expand Down
Loading
Loading