-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better Marten event subscriptions. Closes GH-132
- Loading branch information
1 parent
f860b17
commit c70402e
Showing
7 changed files
with
247 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using Wolverine.Runtime; | ||
using Wolverine.Runtime.Routing; | ||
|
||
namespace Wolverine; | ||
|
||
public sealed partial class WolverineOptions | ||
{ | ||
internal readonly List<IMessageTransformation> MessageTransformations = new(); | ||
|
||
internal readonly List<IMessageRouteSource> InternalRouteSources = new() | ||
{ | ||
new TransformedMessageRouteSource(), | ||
new ExplicitRouting(), | ||
new LocalRouting(), | ||
new MessageRoutingConventions() | ||
}; | ||
|
||
internal readonly List<IMessageRouteSource> CustomRouteSources = new(); | ||
|
||
internal IEnumerable<IMessageRouteSource> RouteSources() | ||
{ | ||
foreach (var routeSource in CustomRouteSources) | ||
{ | ||
yield return routeSource; | ||
} | ||
|
||
foreach (var routeSource in InternalRouteSources) | ||
{ | ||
yield return routeSource; | ||
} | ||
} | ||
|
||
|
||
/// <summary> | ||
/// Advanced usage of Wolverine to register programmatic message routing rules | ||
/// </summary> | ||
/// <param name="messageRouteSource"></param> | ||
public void PublishWithMessageRoutingSource(IMessageRouteSource messageRouteSource) | ||
{ | ||
CustomRouteSources.Add(messageRouteSource); | ||
} | ||
} | ||
|
||
internal interface IMessageTransformation | ||
{ | ||
Type SourceType { get; } | ||
Type DestinationType { get; } | ||
IMessageRoute CreateRoute(IMessageRoute inner); | ||
} | ||
|
||
internal class MessageTransformation<TSource, TDestination> : IMessageTransformation | ||
{ | ||
private readonly Func<TSource, TDestination> _transformation; | ||
|
||
public MessageTransformation(Func<TSource, TDestination> transformation) | ||
{ | ||
_transformation = transformation; | ||
} | ||
|
||
public Type SourceType => typeof(TSource); | ||
public Type DestinationType => typeof(TDestination); | ||
public IMessageRoute CreateRoute(IMessageRoute inner) | ||
{ | ||
return new TransformedMessageRoute<TSource, TDestination>(_transformation, inner); | ||
} | ||
} |