4
4
5
5
namespace InertiaNetCore . Models ;
6
6
7
- public class InertiaOptions
7
+ public record InertiaJsonOptions
8
8
{
9
- public string RootView { get ; set ; } = "~/Views/App.cshtml" ;
9
+ private InertiaJsonOptions ( )
10
+ {
11
+ }
10
12
11
- public bool SsrEnabled { get ; set ; } = false ;
12
- public string SsrUrl { get ; set ; } = "http://127.0.0.1:13714/render" ;
13
-
14
- public Action < SessionOptions > ConfigureSession { get ; set ; } = _ => { } ;
15
-
16
- public bool EncryptHistory { get ; set ; }
17
-
18
- private static JsonSerializerOptions DefaultJsonSerializerOptions { get ; } = new ( )
13
+ internal object Options { get ; private init ; } = new JsonSerializerOptions
19
14
{
20
15
PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
21
16
ReferenceHandler = ReferenceHandler . IgnoreCycles ,
22
17
DictionaryKeyPolicy = JsonNamingPolicy . CamelCase
23
18
} ;
24
19
25
- public object JsonSerializerOptions { get ; set ; } = DefaultJsonSerializerOptions ;
26
-
27
- public Func < object , InertiaOptions , string > JsonSerializeFn { get ; set ; } = ( model , o ) =>
20
+ private Func < object , object , string > SerializeFn { get ; init ; } = ( model , options )
21
+ => JsonSerializer . Serialize ( model , options as JsonSerializerOptions ) ;
22
+
23
+ internal string Serialize ( object model ) => SerializeFn ( model , Options ) ;
24
+
25
+ public static InertiaJsonOptions Default { get ; } = new ( ) ;
26
+
27
+ public static InertiaJsonOptions Create < T > ( T options , Func < object , T , string > ? serialize = null ) where T : class
28
28
{
29
- return JsonSerializer . Serialize ( model , o . JsonSerializerOptions as JsonSerializerOptions ) ;
30
- } ;
29
+ serialize ??= ( model , jo ) => JsonSerializer . Serialize ( model , jo as JsonSerializerOptions ) ;
30
+ return new InertiaJsonOptions
31
+ {
32
+ Options = options ,
33
+ SerializeFn = ( model , jo ) => serialize ( model , ( jo as T ) ! )
34
+ } ;
35
+ }
31
36
}
37
+
38
+ public class InertiaOptions
39
+ {
40
+ public string RootView { get ; set ; } = "~/Views/App.cshtml" ;
41
+
42
+ public bool SsrEnabled { get ; set ; } = false ;
43
+ public string SsrUrl { get ; set ; } = "http://127.0.0.1:13714/render" ;
44
+
45
+ public Action < SessionOptions > ConfigureSession { get ; set ; } = _ => { } ;
46
+
47
+ public bool EncryptHistory { get ; set ; }
48
+
49
+ public InertiaJsonOptions Json { get ; set ; } = InertiaJsonOptions . Default ;
50
+ }
0 commit comments