Skip to content

Commit c3711d6

Browse files
committed
Avoid losing caller information when invoking extension methods
The message bus extension methods for parameterless commands/events was missing the caller member arguments and thus causing an inconsistent behavior.
1 parent 7f03d95 commit c3711d6

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/Merq/IMessageBusExtensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using System.Runtime.CompilerServices;
23

34
namespace Merq;
45

@@ -11,13 +12,13 @@ public static class IMessageBusExtensions
1112
/// <summary>
1213
/// Notifies the bus of a new event instance of <typeparamref name="TEvent"/>.
1314
/// </summary>
14-
public static void Notify<TEvent>(this IMessageBus bus) where TEvent : new()
15-
=> bus.Notify(new TEvent());
15+
public static void Notify<TEvent>(this IMessageBus bus, [CallerMemberName] string? callerName = default, [CallerFilePath] string? callerFile = default, [CallerLineNumber] int? callerLine = default) where TEvent : new()
16+
=> bus.Notify(new TEvent(), callerName, callerFile, callerLine);
1617

1718
/// <summary>
1819
/// Executes the given synchronous command.
1920
/// </summary>
2021
/// <typeparam name="TCommand">The type of command to create and execute.</typeparam>
21-
public static void Execute<TCommand>(this IMessageBus bus) where TCommand : ICommand, new()
22-
=> bus.Execute(new TCommand());
22+
public static void Execute<TCommand>(this IMessageBus bus, [CallerMemberName] string? callerName = default, [CallerFilePath] string? callerFile = default, [CallerLineNumber] int? callerLine = default) where TCommand : ICommand, new()
23+
=> bus.Execute(new TCommand(), callerName, callerFile, callerLine);
2324
}

0 commit comments

Comments
 (0)