@@ -27,6 +27,7 @@ public class MessagePackHubProtocol : IHubProtocol
2727 private const int NonVoidResult = 3 ;
2828
2929 private readonly MessagePackSerializerOptions _msgPackSerializerOptions ;
30+
3031 private static readonly string ProtocolName = "messagepack" ;
3132 private static readonly int ProtocolVersion = 1 ;
3233
@@ -52,37 +53,7 @@ public MessagePackHubProtocol()
5253 /// <param name="options">The options used to initialize the protocol.</param>
5354 public MessagePackHubProtocol ( IOptions < MessagePackHubProtocolOptions > options )
5455 {
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 ;
8657 }
8758
8859 /// <inheritdoc />
@@ -656,17 +627,17 @@ private static object DeserializeObject(ref MessagePackReader reader, Type type,
656627 }
657628 }
658629
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 ) ;
664635
665636 internal class SignalRResolver : IFormatterResolver
666637 {
667638 public static readonly IFormatterResolver Instance = new SignalRResolver ( ) ;
668639
669- public static readonly IList < IFormatterResolver > Resolvers = new IFormatterResolver [ ]
640+ public static readonly IReadOnlyList < IFormatterResolver > Resolvers = new IFormatterResolver [ ]
670641 {
671642 DynamicEnumAsStringResolver . Instance ,
672643 ContractlessStandardResolver . Instance ,
0 commit comments