@@ -26,7 +26,7 @@ public class MessagePackHubProtocol : IHubProtocol
26
26
private const int VoidResult = 2 ;
27
27
private const int NonVoidResult = 3 ;
28
28
29
- private MessagePackSerializerOptions _msgPackSerializerOptions ;
29
+ private readonly MessagePackSerializerOptions _msgPackSerializerOptions ;
30
30
private static readonly string ProtocolName = "messagepack" ;
31
31
private static readonly int ProtocolVersion = 1 ;
32
32
@@ -53,34 +53,36 @@ public MessagePackHubProtocol()
53
53
public MessagePackHubProtocol ( IOptions < MessagePackHubProtocolOptions > options )
54
54
{
55
55
var msgPackOptions = options . Value ;
56
- SetupResolver ( msgPackOptions ) ;
57
- _msgPackSerializerOptions . WithSecurity ( MessagePackSecurity . UntrustedData ) ;
58
- }
56
+ var resolver = SignalRResolver . Instance ;
57
+ var hasCustomFormatterResolver = false ;
59
58
60
- private void SetupResolver ( MessagePackHubProtocolOptions options )
61
- {
62
- // if counts don't match then we know users customized resolvers so we set up the options
63
- // with the provided resolvers
64
- if ( options . FormatterResolvers . Count != SignalRResolver . Resolvers . Count )
59
+ // if counts don't match then we know users customized resolvers so we set up the options with the provided resolvers
60
+ if ( msgPackOptions . FormatterResolvers . Count != SignalRResolver . Resolvers . Count )
65
61
{
66
- var resolver = CompositeResolver . Create ( Array . Empty < IMessagePackFormatter > ( ) , ( IReadOnlyList < IFormatterResolver > ) options . FormatterResolvers ) ;
67
- _msgPackSerializerOptions = MessagePackSerializerOptions . Standard . WithResolver ( resolver ) ;
68
- return ;
62
+ hasCustomFormatterResolver = true ;
69
63
}
70
-
71
- for ( var i = 0 ; i < options . FormatterResolvers . Count ; i ++ )
64
+ else
72
65
{
73
- // check if the user customized the resolvers
74
- if ( options . FormatterResolvers [ i ] != SignalRResolver . Resolvers [ i ] )
66
+ // Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<>
67
+ for ( var i = 0 ; i < msgPackOptions . FormatterResolvers . Count ; i ++ )
75
68
{
76
- var resolver = CompositeResolver . Create ( Array . Empty < IMessagePackFormatter > ( ) , ( IReadOnlyList < IFormatterResolver > ) options . FormatterResolvers ) ;
77
- _msgPackSerializerOptions = MessagePackSerializerOptions . Standard . WithResolver ( resolver ) ;
78
- return ;
69
+ // check if the user customized the resolvers
70
+ if ( msgPackOptions . FormatterResolvers [ i ] != SignalRResolver . Resolvers [ i ] )
71
+ {
72
+ hasCustomFormatterResolver = true ;
73
+ break ;
74
+ }
79
75
}
80
76
}
81
77
82
- // Use optimized cached resolver if the default is chosen
83
- _msgPackSerializerOptions = MessagePackSerializerOptions . Standard . WithResolver ( SignalRResolver . Instance ) ;
78
+ if ( hasCustomFormatterResolver )
79
+ {
80
+ resolver = CompositeResolver . Create ( Array . Empty < IMessagePackFormatter > ( ) , ( IReadOnlyList < IFormatterResolver > ) msgPackOptions . FormatterResolvers ) ;
81
+ }
82
+
83
+ _msgPackSerializerOptions = MessagePackSerializerOptions . Standard
84
+ . WithResolver ( resolver )
85
+ . WithSecurity ( MessagePackSecurity . UntrustedData ) ;
84
86
}
85
87
86
88
/// <inheritdoc />
0 commit comments