Table of Contents

Class RequestContextPipelineExtensions

Namespace
IceRpc
Assembly
IceRpc.RequestContext.dll

Provides an extension method for Pipeline to add the request context interceptor.

public static class RequestContextPipelineExtensions
Inheritance
RequestContextPipelineExtensions
Inherited Members

Methods

UseRequestContext(Pipeline)

Adds a RequestContextInterceptor to this pipeline.

public static Pipeline UseRequestContext(this Pipeline pipeline)

Parameters

pipeline Pipeline

The pipeline being configured.

Returns

Pipeline

The pipeline being configured.

Examples

The following code adds the request context interceptor to the invocation pipeline.

// Create a client connection.
await using var connection = new ClientConnection(new Uri("icerpc://localhost"));

// Add the request context interceptor to the invocation pipeline.
Pipeline pipeline = new Pipeline()
    .UseRequestContext()
    .Into(connection);

// Create a feature collection holding an IRequestContextFeature.
IFeatureCollection features = new FeatureCollection().With<IRequestContextFeature>(
    new RequestContextFeature
    {
        ["UserId"] = Environment.UserName.ToLowerInvariant(),
        ["MachineName"] = Environment.MachineName
    });

The following code shows how to set the request context feature with a Slice proxy.

// The request context interceptor encodes the request context feature into the request context field.
var greeter = new GreeterProxy(pipeline);
string greeting = await greeter.GreetAsync(Environment.UserName, features);

The following code shows how to set the request context feature with a Protobuf client.

// The request context interceptor encodes the request context feature into the request context field.
var greeter = new GreeterClient(pipeline);
GreetResponse response = await greeter.GreetAsync(new GreetRequest { Name = Environment.UserName }, features);
See Also