Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 热巧克力:如何访问;“初始连接”;有效载荷_C#_Asp.net Core_.net Core_Hotchocolate - Fatal编程技术网

C# 热巧克力:如何访问;“初始连接”;有效载荷

C# 热巧克力:如何访问;“初始连接”;有效载荷,c#,asp.net-core,.net-core,hotchocolate,C#,Asp.net Core,.net Core,Hotchocolate,我们正在连接_init期间发送额外的有效负载(阿波罗的connectionParams in) 我在官方来源中找不到关于如何提取此类信息的任何信息,也找不到关于任何消息中间件/处理程序的任何信息 并发解决方案graphql dotnet允许我像这样实现IOperationMessageListener public class SusbcriptionInitListener: IOperationMessageListener { public Task BeforeHandleAsy

我们正在连接_init期间发送额外的有效负载(阿波罗的connectionParams in)

我在官方来源中找不到关于如何提取此类信息的任何信息,也找不到关于任何消息中间件/处理程序的任何信息

并发解决方案graphql dotnet允许我像这样实现IOperationMessageListener

public class SusbcriptionInitListener: IOperationMessageListener
{
    public Task BeforeHandleAsync(MessageHandlingContext context) => Task.CompletedTask;
    
    // This method will be triggered with every incoming message
    public async Task HandleAsync(MessageHandlingContext context)
    {
        var message = context.Message;
        
        // I can then filter for specific message type and do something with the raw playload
        if (message.Type == MessageType.GQL_CONNECTION_INIT)
        {
            string myInformation = message.Payload.GetValue("MyInfomration").ToString();
            
            DoSomethingWithMyInformation(myInformation);
        }
    }

    public Task AfterHandleAsync(MessageHandlingContext context) => Task.CompletedTask;
}

HC是否提供类似的功能?

您需要的是
ISocketSessionInterceptor

服务
AddGraphQLServer()
... 你的配置
.AddSocketSessionInterceptor();
公共接口ISocketSessionInterceptor
{
ValueTaskOnConnectAsync(
等电位连接,
InitializeConnectionMessage消息,
取消令牌取消令牌);
ValueTaskOnRequestAsync(
等电位连接,
IQueryRequestBuilder请求生成器,
取消令牌取消令牌);
ValueTaskOnCloseAsync(
等电位连接,
取消令牌取消令牌);
}
您可以通过覆盖
OnConnectAsync
来访问连接请求负载

InitializeConnectionMessage
包含一个保存有效负载的
Payload
属性