Skip to content

Commit

Permalink
Added a few extension methods to rebus, allowing passing a customizer…
Browse files Browse the repository at this point in the history
… Action to main message/event submission methods
  • Loading branch information
pruiz committed Nov 26, 2015
1 parent 1c06a4d commit 3925a66
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions HermaFx.Rebus/HermaFx.Rebus.csproj 100755 → 100644
Expand Up @@ -40,6 +40,7 @@
<ItemGroup>
<Compile Include="MessageDateExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RebusExtensions.cs" />
<Compile Include="TimeToBeReceivedExtensions.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
56 changes: 56 additions & 0 deletions HermaFx.Rebus/RebusExtensions.cs
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Rebus;

namespace HermaFx.Rebus
{
public static class RebusExtensions
{
public static void Send<TCommand>(this IBus bus, Action<TCommand> customizer)
where TCommand : new()
{
Guard.IsNotNull(bus, "bus");

var message = Activator.CreateInstance<TCommand>();
if (customizer != null) customizer(message);

bus.Send(message);
}

public static void SendLocal<TCommand>(this IBus bus, Action<TCommand> customizer)
where TCommand : new()
{
Guard.IsNotNull(bus, "bus");

var message = Activator.CreateInstance<TCommand>();
if (customizer != null) customizer(message);

bus.Send(message);
}

public static void Publish<TEvent>(this IBus bus, Action<TEvent> customizer)
where TEvent : new()
{
Guard.IsNotNull(bus, "bus");

var message = Activator.CreateInstance<TEvent>();
if (customizer != null) customizer(message);

bus.Publish(message);
}

public static void Reply<TResponse>(this IBus bus, Action<TResponse> customizer)
where TResponse : new()
{
Guard.IsNotNull(bus, "bus");

var message = Activator.CreateInstance<TResponse>();
if (customizer != null) customizer(message);

bus.Reply(message);
}
}
}

0 comments on commit 3925a66

Please sign in to comment.