/// <summary> /// Add Distributed Context entry to the builder. /// </summary> /// <param name="entry">Entry to add to the context.</param> /// <returns>The current <see cref="DistributedContextBuilder"/> instance.</returns> public DistributedContextBuilder Add(DistributedContextEntry entry) { if (DistributedContext.Carrier is NoopDistributedContextCarrier || entry == default) { return(this); } if (this.entries == null) { this.entries = new List <DistributedContextEntry>(); } else { for (int i = 0; i < this.entries.Count; i++) { if (this.entries[i].Key == entry.Key) { this.entries[i] = entry; return(this); } } } this.entries.Add(entry); return(this); }
/// <summary> /// Create <see cref="DistributedContext"/> instance from entry. /// </summary> /// <param name="entry">Entry to add to the context.</param> /// <returns>Instance of <see cref="DistributedContext"/>.</returns> public static DistributedContext CreateContext(DistributedContextEntry entry) => new DistributedContextBuilder(inheritCurrentContext: false).Add(entry).Build();