Class ChannelExtensions
Provides extension methods to make it easy to register interceptors on Channel objects.
Inheritance
Namespace: Grpc.Core.Interceptors
Assembly: Grpc.Core.Api.dll
Syntax
public static class ChannelExtensions : object
Methods
Intercept(ChannelBase, Func<Metadata, Metadata>)
Returns a CallInvoker instance that intercepts the invoker with the given interceptor.
Declaration
public static CallInvoker Intercept(this ChannelBase channel, Func<Metadata, Metadata> interceptor)
Parameters
Type | Name | Description |
---|---|---|
ChannelBase | channel | The channel to intercept. |
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.
Intercept(ChannelBase, Interceptor)
Returns a CallInvoker instance that intercepts the channel with the given interceptor.
Declaration
public static CallInvoker Intercept(this ChannelBase channel, Interceptor interceptor)
Parameters
Type | Name | Description |
---|---|---|
ChannelBase | 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(ChannelBase, Interceptor[])
Returns a CallInvoker instance that intercepts the channel with the given interceptors.
Declaration
public static CallInvoker Intercept(this ChannelBase channel, params Interceptor[] interceptors)
Parameters
Type | Name | Description |
---|---|---|
ChannelBase | 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.