@@ -31,25 +31,11 @@ public sealed class BiDi : IAsyncDisposable
3131{
3232 private readonly ConcurrentDictionary < Type , Module > _modules = new ( ) ;
3333
34- private readonly JsonSerializerOptions _jsonOptions ;
35-
3634 private BiDi ( string url )
3735 {
3836 var uri = new Uri ( url ) ;
3937
4038 Broker = new Broker ( this , uri ) ;
41-
42- _jsonOptions = new JsonSerializerOptions
43- {
44- PropertyNameCaseInsensitive = true ,
45- PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
46- DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingNull ,
47-
48- Converters =
49- {
50- new DateTimeOffsetConverter ( ) ,
51- }
52- } ;
5339 }
5440
5541 private Broker Broker { get ; }
@@ -101,6 +87,20 @@ public async ValueTask DisposeAsync()
10187
10288 public T AsModule < T > ( ) where T : Module , new ( )
10389 {
104- return ( T ) _modules . GetOrAdd ( typeof ( T ) , _ => Module . Create < T > ( this , Broker , _jsonOptions ) ) ;
90+ return ( T ) _modules . GetOrAdd ( typeof ( T ) , _ => Module . Create < T > ( this , Broker , CreateDefaultJsonOptions ( ) ) ) ;
91+ }
92+
93+ private static JsonSerializerOptions CreateDefaultJsonOptions ( )
94+ {
95+ return new JsonSerializerOptions
96+ {
97+ PropertyNameCaseInsensitive = true ,
98+ PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
99+ DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingNull ,
100+ Converters =
101+ {
102+ new DateTimeOffsetConverter ( ) ,
103+ }
104+ } ;
105105 }
106106}
0 commit comments