Skip to content

Commit 3c483c1

Browse files
committed
处理mqtt取上下文信息的问题
1 parent 871d9bd commit 3c483c1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Source/Routing/MqttBaseController.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
// Copyright (c) Atlas Lift Tech Inc. All rights reserved.
22

33
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Logging;
6+
using Microsoft.Extensions.Options;
7+
using MQTTnet;
8+
using MQTTnet.AspNetCore.AttributeRouting;
49
using MQTTnet.AspNetCore.AttributeRouting.Attributes;
510
using MQTTnet.AspNetCore.AttributeRouting.Routing;
611
using MQTTnet.Server;
12+
using System;
13+
using System.Collections.Generic;
714
using System.Linq;
815
using System.Threading.Tasks;
916

@@ -80,5 +87,15 @@ public virtual Task BadMessage()
8087
MqttContext.ProcessPublish = false;
8188
return Task.CompletedTask;
8289
}
90+
91+
public T GetSessionItem<T>(string key)
92+
{
93+
return (T)MqttContext.SessionItems[key] ;
94+
}
95+
96+
public T GetSessionItem<T>()
97+
{
98+
return (T)MqttContext.SessionItems[nameof(T)];
99+
}
83100
}
84101
}

0 commit comments

Comments
 (0)