Interface IRequestContextFeature
Represents a feature that holds a read-only dictionary of strings. This feature can be transmitted as a Context field with both ice and icerpc.
public interface IRequestContextFeature
Examples
The following code shows how to update the request context from an interceptor.
// An interceptor that adds an entry to the request context. Since IRequestContextFeature.Value is
// read-only, the pattern is to retrieve the existing entries as an ImmutableDictionary, add the new
// entry to produce a new ImmutableDictionary, then install a new feature wrapping the result.
_ = new Pipeline()
.Use(next => new InlineInvoker((request, cancellationToken) =>
{
IRequestContextFeature? feature = request.Features.Get<IRequestContextFeature>();
ImmutableDictionary<string, string> dictionary =
feature?.Value.ToImmutableDictionary() ?? ImmutableDictionary<string, string>.Empty;
dictionary = dictionary.Add("CorrelationId", Guid.NewGuid().ToString());
request.Features = request.Features.With<IRequestContextFeature>(
new RequestContextFeature(dictionary));
return next.InvokeAsync(request, cancellationToken);
}))
.UseRequestContext();
Remarks
An interceptor that needs to add or remove context entries should build a new dictionary and install a new IRequestContextFeature.
Properties
Value
Gets the value of this feature.
IReadOnlyDictionary<string, string> Value { get; }
Property Value
- IReadOnlyDictionary<string, string>
The request context.