Show / Hide Table of Contents

Class ChannelExtensions

Provides extension methods to make it easy to register interceptors on Channel objects.

Inheritance
System.Object
ChannelExtensions
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Grpc.Core.Interceptors
Assembly: Grpc.Core.dll
Syntax
public static class ChannelExtensions

Methods

Intercept(Channel, Interceptor)

Returns a CallInvoker instance that intercepts the channel with the given interceptor.

Declaration
public static CallInvoker Intercept(this Channel channel, Interceptor interceptor)
Parameters
Type Name Description
Channel channel

The channel to intercept.

Interceptor interceptor

The interceptor to intercept the channel with.

Returns
Type Description
CallInvoker
Remarks

Multiple interceptors can be added on top of each other by calling "channel.Intercept(a, b, c)". The order of invocation will be "a", "b", and then "c". Interceptors can be later added to an existing intercepted channel, effectively building a chain like "channel.Intercept(c).Intercept(b).Intercept(a)". Note that in this case, the last interceptor added will be the first to take control.

Intercept(Channel, Interceptor[])

Returns a CallInvoker instance that intercepts the channel with the given interceptors.

Declaration
public static CallInvoker Intercept(this Channel channel, params Interceptor[] interceptors)
Parameters
Type Name Description
Channel channel

The channel to intercept.

Interceptor[] interceptors

An array of interceptors to intercept the channel with. Control is passed to the interceptors in the order specified.

Returns
Type Description
CallInvoker
Remarks

Multiple interceptors can be added on top of each other by calling "channel.Intercept(a, b, c)". The order of invocation will be "a", "b", and then "c". Interceptors can be later added to an existing intercepted channel, effectively building a chain like "channel.Intercept(c).Intercept(b).Intercept(a)". Note that in this case, the last interceptor added will be the first to take control.

Intercept(Channel, Func<Metadata, Metadata>)

Returns a CallInvoker instance that intercepts the invoker with the given interceptor.

Declaration
public static CallInvoker Intercept(this Channel channel, Func<Metadata, Metadata> interceptor)
Parameters
Type Name Description
Channel channel

The channel to intercept.

System.Func<Metadata, Metadata> interceptor

An interceptor delegate that takes the request metadata to be sent with an outgoing call and returns a Metadata instance that will replace the existing invocation metadata.

Returns
Type Description
CallInvoker
Remarks

Multiple interceptors can be added on top of each other by building a chain like "channel.Intercept(c).Intercept(b).Intercept(a)". Note that in this case, the last interceptor added will be the first to take control.

Back to top