forked from huysentruitw/Aggregator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandHandlingContext.cs
30 lines (27 loc) · 1.12 KB
/
CommandHandlingContext.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System.Collections.Generic;
namespace Aggregator.Command
{
/// <summary>
/// This class keeps track of the command handling context for the lifetime of a single command.
/// </summary>
public sealed class CommandHandlingContext
{
private readonly Dictionary<string, object> _properties = new Dictionary<string, object>();
/// <summary>
/// Sets a context property.
/// </summary>
/// <typeparam name="T">The property value type.</typeparam>
/// <param name="key">The property key.</param>
/// <param name="value">The property value.</param>
public void Set<T>(string key, T value)
=> _properties[key] = value;
/// <summary>
/// Gets a context property.
/// </summary>
/// <typeparam name="T">The property value type.</typeparam>
/// <param name="key">The property key.</param>
/// <returns>The property value or default in case the property was not found.</returns>
public T Get<T>(string key)
=> _properties.TryGetValue(key, out var value) ? (T)value : default(T);
}
}