Skip to content

Commit

Permalink
Add Tags to IExecutionContext
Browse files Browse the repository at this point in the history
  • Loading branch information
litenova committed Jan 30, 2024
1 parent d1f0d7d commit c3b511f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## v.0.24.1
- Add `Tags` to `IExecutionContext`.

## v.0.24.0
- Upgraded to .NET 8.

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<Authors>A. Shafie</Authors>
<PackageTags>mediator;cqrs</PackageTags>
<VersionPrefix>0.24.0</VersionPrefix>
<VersionPrefix>0.24.1</VersionPrefix>
<PackageIcon>icon.png</PackageIcon>
<Description>LiteBus is an easy-to-use and ambitious in-process mediator providing the foundation to implement Command Query Separation (CQS). It is implemented with minimal reflection and instead utilizes covariance and contravariance to provide its core functionality.</Description>
<PackageProjectUrl>https://github.com/litenova/LiteBus</PackageProjectUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public interface IExecutionContext
/// Gets a key/value collection that can be used to share data within the scope of this execution.
/// </summary>
IDictionary<object, object?> Items { get; }

/// <summary>
/// Gets the collection of specified tags used to filter message handlers (i.e., pre, main and post) during mediation.
/// </summary>
IReadOnlyCollection<string> Tags { get; }
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
#nullable enable

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using LiteBus.Messaging.Abstractions;

namespace LiteBus.Messaging.Internal.Contexts.Execution;

/// <summary>
/// Represents the execution context for a specific operation or task.
/// </summary>
/// <inheritdoc cref="IExecutionContext"/>
internal sealed class ExecutionContext : IExecutionContext
{
/// <summary>
/// Initializes a new instance of the <see cref="ExecutionContext"/> class with the specified cancellation token.
/// </summary>
/// <param name="cancellationToken">The cancellation token associated with the execution context.</param>
public ExecutionContext(CancellationToken cancellationToken)
public ExecutionContext(CancellationToken cancellationToken, IEnumerable<string> tags)
{
CancellationToken = cancellationToken;
Tags = tags.ToList();
}

/// <summary>
/// Gets the cancellation token associated with the execution context.
/// </summary>
public CancellationToken CancellationToken { get; }

/// <summary>
/// Gets or sets a key/value collection that can be used to share data within the scope of this execution.
/// </summary>
public IDictionary<object, object?> Items { get; } = new Dictionary<object, object?>();

public IReadOnlyCollection<string> Tags { get; }
}
2 changes: 1 addition & 1 deletion src/LiteBus.Messaging/Internal/Mediator/MessageMediator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed class MessageMediator : IMessageMediator
var originalExecutionContext = AmbientExecutionContext.Current;

// Create a new execution context for the current scope
AmbientExecutionContext.Current = new ExecutionContext(options.CancellationToken);
AmbientExecutionContext.Current = new ExecutionContext(options.CancellationToken, options.Tags);

// Get the actual type of the message
var messageType = message.GetType();
Expand Down

0 comments on commit c3b511f

Please sign in to comment.