using System; using System.Collections.Generic; using System.Threading.Tasks; using Tapeti.Config; namespace Tapeti.Default { internal class MessageContext : IMessageContext { private readonly Dictionary items = new Dictionary(); /// public ITapetiConfig Config { get; set; } /// public string Queue { get; set; } /// public string Exchange { get; set; } /// public string RoutingKey { get; set; } /// public object Message { get; set; } /// public IMessageProperties Properties { get; set; } /// public IBinding Binding { get; set; } /// public void Dispose() { foreach (var item in items.Values) (item as IDisposable)?.Dispose(); } /// public async ValueTask DisposeAsync() { foreach (var item in items.Values) { if (item is IAsyncDisposable asyncDisposable) await asyncDisposable.DisposeAsync(); } } /// public void Store(string key, object value) { items.Add(key, value); } /// public bool Get(string key, out T value) where T : class { if (!items.TryGetValue(key, out var objectValue)) { value = default(T); return false; } value = (T)objectValue; return true; } } }