Skip to content

Commit 2452933

Browse files
author
youri
committed
fix for awaiting null
1 parent fa5c22e commit 2452933

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Source/Extensions/ServiceCollectionExtensions.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ public static IServiceCollection AddMqttControllers(this IServiceCollection serv
3232
{
3333
return services.AddMqttControllers(opt => { });
3434
}
35-
public static IServiceCollection AddMqttControllers(this IServiceCollection services, Action< MqttRoutingOptions> _options)
35+
public static IServiceCollection AddMqttControllers(this IServiceCollection services, Action<MqttRoutingOptions> _options)
3636
{
3737
var _opt = new MqttRoutingOptions();
3838
_opt.WithJsonSerializerOptions();
3939
_opt.FromAssemblies = null;
4040
_opt.RouteInvocationInterceptor = null;
41-
_options?.Invoke( _opt);
42-
41+
_options?.Invoke(_opt);
42+
4343
services.AddSingleton(_opt);
4444
services.AddSingleton(_ =>
4545
{
46-
47-
var fromAssemblies= _opt.FromAssemblies;
46+
47+
var fromAssemblies = _opt.FromAssemblies;
4848
if (fromAssemblies != null && fromAssemblies.Length == 0)
4949
{
5050
throw new ArgumentException("'fromAssemblies' cannot be an empty array. Pass null or a collection of 1 or more assemblies.", nameof(fromAssemblies));
@@ -58,7 +58,7 @@ public static IServiceCollection AddMqttControllers(this IServiceCollection serv
5858
services.AddSingleton<MqttRouter>();
5959
if (_opt.RouteInvocationInterceptor != null)
6060
{
61-
services.AddSingleton(typeof( IRouteInvocationInterceptor), _opt.RouteInvocationInterceptor);
61+
services.AddSingleton(typeof(IRouteInvocationInterceptor), _opt.RouteInvocationInterceptor);
6262
}
6363
return services;
6464
}
@@ -103,10 +103,17 @@ public static IApplicationBuilder UseAttributeRouting(this IApplicationBuilder a
103103
{
104104
try
105105
{
106-
await interceptor?.RouteExecuting(args.ClientId, args.ApplicationMessage);
106+
if (interceptor != null)
107+
{
108+
await interceptor?.RouteExecuting(args.ClientId, args.ApplicationMessage);
109+
}
110+
107111
await router.OnIncomingApplicationMessage(app.ApplicationServices, args, allowUnmatchedRoutes);
108-
await interceptor?.RouteExecuted(args, null);
109112

113+
if (interceptor != null)
114+
{
115+
await interceptor?.RouteExecuted(args, null);
116+
}
110117
}
111118
catch (Exception ex)
112119
{

0 commit comments

Comments
 (0)