Skip to content

Commit 871d9bd

Browse files
committed
将上下文赋值放在参数赋值前面, 便于 topic传参
1 parent 73082a6 commit 871d9bd

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

Source/Routing/MqttRouter.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,7 @@ internal async Task OnIncomingApplicationMessage(IServiceProvider svcProvider, I
7575
})
7676
.ToArray();
7777

78-
if (routeContext.HaveControllerParameter)
79-
{
80-
var tmpx = routeContext.ControllerTemplate;
81-
tmpx.Segments.Where(p => p.IsParameter).ToList().ForEach(ts =>
82-
{
83-
var pro=declaringType.GetRuntimeProperty(ts.Value);
84-
if (pro != null)
85-
{
86-
if ( routeContext.Parameters.TryGetValue(ts.Value,out object pvalue))
87-
{
88-
pro.SetValue(classInstance, pvalue);
89-
}
90-
}
91-
});
92-
}
78+
9379
if (activateProperties.Length == 0)
9480
{
9581
logger.LogDebug($"MqttController '{declaringType.FullName}' does not have a property that can accept a controller context. You may want to add a [{nameof(MqttControllerContextAttribute)}] to a pubilc property.");
@@ -107,6 +93,21 @@ internal async Task OnIncomingApplicationMessage(IServiceProvider svcProvider, I
10793
property.SetValue(classInstance, controllerContext);
10894
}
10995

96+
if (routeContext.HaveControllerParameter)
97+
{
98+
var tmpx = routeContext.ControllerTemplate;
99+
tmpx.Segments.Where(p => p.IsParameter).ToList().ForEach(ts =>
100+
{
101+
var pro = declaringType.GetRuntimeProperty(ts.Value);
102+
if (pro != null)
103+
{
104+
if (routeContext.Parameters.TryGetValue(ts.Value, out object pvalue))
105+
{
106+
pro.SetValue(classInstance, pvalue);
107+
}
108+
}
109+
});
110+
}
110111
ParameterInfo[] parameters = routeContext.Handler.GetParameters();
111112

112113
context.ProcessPublish = true;

0 commit comments

Comments
 (0)