@@ -23,25 +23,38 @@ public interface IJsonSerializerOptionsProvider
2323/// </summary>
2424public class TransportSerializerOptionsProvider : IJsonSerializerOptionsProvider
2525{
26- private readonly JsonSerializerOptions _options = new ( ) ;
26+ private readonly IReadOnlyCollection < JsonConverter > ? _bakedInConverters ;
27+ private readonly IReadOnlyCollection < JsonConverter > ? _userProvidedConverters ;
28+ private readonly Action < JsonSerializerOptions > ? _mutateOptions ;
2729
2830 /// <inheritdoc cref="IJsonSerializerOptionsProvider"/>
29- public JsonSerializerOptions ? CreateJsonSerializerOptions ( ) => _options ;
31+ public JsonSerializerOptions ? CreateJsonSerializerOptions ( )
32+ {
33+ var options = new JsonSerializerOptions ( ) ;
34+ foreach ( var converter in _bakedInConverters ?? [ ] )
35+ options . Converters . Add ( converter ) ;
36+
37+ foreach ( var converter in _userProvidedConverters ?? [ ] )
38+ options . Converters . Add ( converter ) ;
39+
40+ _mutateOptions ? . Invoke ( options ) ;
41+
42+ return options ;
43+ }
3044
3145 /// <inheritdoc cref="TransportSerializerOptionsProvider"/>
3246 public TransportSerializerOptionsProvider ( ) { }
3347
3448 /// <inheritdoc cref="TransportSerializerOptionsProvider"/>
35- public TransportSerializerOptionsProvider ( IReadOnlyCollection < JsonConverter > bakedIn , IReadOnlyCollection < JsonConverter > ? userProvided , Action < JsonSerializerOptions > ? optionsAction = null )
49+ public TransportSerializerOptionsProvider (
50+ IReadOnlyCollection < JsonConverter > bakedInConverters ,
51+ IReadOnlyCollection < JsonConverter > ? userProvidedConverters ,
52+ Action < JsonSerializerOptions > ? mutateOptions = null
53+ )
3654 {
37- foreach ( var converter in bakedIn )
38- _options . Converters . Add ( converter ) ;
39-
40- foreach ( var converter in userProvided ?? [ ] )
41- _options . Converters . Add ( converter ) ;
42-
43- optionsAction ? . Invoke ( _options ) ;
44-
55+ _bakedInConverters = bakedInConverters ;
56+ _userProvidedConverters = userProvidedConverters ;
57+ _mutateOptions = mutateOptions ;
4558 }
4659}
4760
0 commit comments