Skip to content

Commit

Permalink
more expressivity in queue configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ppossanzini committed Nov 18, 2024
1 parent 9072240 commit 50f69e1
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions Arbitrer/extensions/ArbitrerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -312,15 +313,46 @@ public static bool IsNotification(this Type t)
return typeof(INotification).IsAssignableFrom(t) && !typeof(IBaseRequest).IsAssignableFrom(t);
}

public static ArbitrerOptions SetTypeQueueName<T>(this ArbitrerOptions options, string queueName)
public static ArbitrerOptions SetTypeQueueName<T>(this ArbitrerOptions options, string queueName)
{
if (options.QueueNames.ContainsKey(typeof(T)))
options.SetTypeQueueName(typeof(T), queueName);
return options;
}

public static ArbitrerOptions SetTypeQueueName(this ArbitrerOptions options, Type type, string queueName)
{
if (options.QueueNames.ContainsKey(type))
{
options.QueueNames[typeof(T)] = queueName;
options.QueueNames[type] = queueName;
}
else
{
options.QueueNames.Add(typeof(T), queueName);
options.QueueNames.Add(type, queueName);
}

return options;
}

public static ArbitrerOptions SetTypesQueueName(this ArbitrerOptions options, Func<IEnumerable<Type>> typeselect, Func<Type, string> typeNameFunction)
{
var types = typeselect();
foreach (var t in types)
{
var result = typeNameFunction(t);
options.SetTypeQueueName(t, result);
}

return options;
}

public static ArbitrerOptions SetTypesQueueName(this ArbitrerOptions options, Func<IEnumerable<Type>> typeselect, Func<string, string> typeNameFunction)
{
var types = typeselect();
foreach (var t in types)
{
var name = t.ArbitrerTypeName(options);
var result = typeNameFunction(name);
options.SetTypeQueueName(t, result);
}

return options;
Expand Down Expand Up @@ -357,11 +389,11 @@ where typeof(INotification).IsAssignableFrom(t)


/// <summary>
/// Gets the queue name for the specified type.
/// Gets the type name used for the specified type.
/// </summary>
/// <param name="t">The type.</param>
/// <param name="sb">The <see cref="StringBuilder"/> instance to append the queue name to (optional).</param>
/// <returns>The queue name for the specified type.</returns>
/// <param name="sb">The <see cref="StringBuilder"/> instance to append the type name to (optional).</param>
/// <returns>The type name for the specified type.</returns>
public static string ArbitrerTypeName(this Type t, ArbitrerOptions options, StringBuilder sb = null)
{
if (t.CustomAttributes.Any())
Expand Down

0 comments on commit 50f69e1

Please sign in to comment.