@@ -27,6 +27,7 @@ public class MessagePackHubProtocol : IHubProtocol
27
27
private const int NonVoidResult = 3 ;
28
28
29
29
private readonly MessagePackSerializerOptions _msgPackSerializerOptions ;
30
+
30
31
private static readonly string ProtocolName = "messagepack" ;
31
32
private static readonly int ProtocolVersion = 1 ;
32
33
@@ -52,37 +53,7 @@ public MessagePackHubProtocol()
52
53
/// <param name="options">The options used to initialize the protocol.</param>
53
54
public MessagePackHubProtocol ( IOptions < MessagePackHubProtocolOptions > options )
54
55
{
55
- var msgPackOptions = options . Value ;
56
- var resolver = SignalRResolver . Instance ;
57
- var hasCustomFormatterResolver = false ;
58
-
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 )
61
- {
62
- hasCustomFormatterResolver = true ;
63
- }
64
- else
65
- {
66
- // Compare each "reference" in the FormatterResolvers IList<> against the default "SignalRResolver.Resolvers" IList<>
67
- for ( var i = 0 ; i < msgPackOptions . FormatterResolvers . Count ; i ++ )
68
- {
69
- // check if the user customized the resolvers
70
- if ( msgPackOptions . FormatterResolvers [ i ] != SignalRResolver . Resolvers [ i ] )
71
- {
72
- hasCustomFormatterResolver = true ;
73
- break ;
74
- }
75
- }
76
- }
77
-
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 ) ;
56
+ _msgPackSerializerOptions = options . Value . SerializerOptions ;
86
57
}
87
58
88
59
/// <inheritdoc />
@@ -656,17 +627,17 @@ private static object DeserializeObject(ref MessagePackReader reader, Type type,
656
627
}
657
628
}
658
629
659
- internal static List < IFormatterResolver > CreateDefaultFormatterResolvers ( )
660
- {
661
- // Copy to allow users to add/remove resolvers without changing the static SignalRResolver list
662
- return new List < IFormatterResolver > ( SignalRResolver . Resolvers ) ;
663
- }
630
+ internal static MessagePackSerializerOptions CreateDefaultMessagePackSerializerOptions ( ) =>
631
+ MessagePackSerializerOptions
632
+ . Standard
633
+ . WithResolver ( SignalRResolver . Instance )
634
+ . WithSecurity ( MessagePackSecurity . UntrustedData ) ;
664
635
665
636
internal class SignalRResolver : IFormatterResolver
666
637
{
667
638
public static readonly IFormatterResolver Instance = new SignalRResolver ( ) ;
668
639
669
- public static readonly IList < IFormatterResolver > Resolvers = new IFormatterResolver [ ]
640
+ public static readonly IReadOnlyList < IFormatterResolver > Resolvers = new IFormatterResolver [ ]
670
641
{
671
642
DynamicEnumAsStringResolver . Instance ,
672
643
ContractlessStandardResolver . Instance ,
0 commit comments