1
1
using System . Diagnostics . CodeAnalysis ;
2
2
3
+ using GenHTTP . Api . Infrastructure ;
4
+
5
+ using GenHTTP . Modules . Conversion . Providers ;
3
6
using GenHTTP . Modules . Layouting . Provider ;
7
+ using GenHTTP . Modules . Reflection . Injectors ;
8
+ using GenHTTP . Modules . Webservices . Provider ;
4
9
5
10
namespace GenHTTP . Modules . Webservices
6
11
{
@@ -17,9 +22,11 @@ public static class Extensions
17
22
/// </summary>
18
23
/// <typeparam name="T">The type of the resource to be added</typeparam>
19
24
/// <param name="path">The path the resource should be available at</param>
20
- public static LayoutBuilder AddService < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . All ) ] T > ( this LayoutBuilder layout , string path ) where T : new ( )
25
+ /// <param name="injectors">Optionally the injectors to be used by this service</param>
26
+ /// <param name="formats">Optionally the formats to be used by this service</param>
27
+ public static LayoutBuilder AddService < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . All ) ] T > ( this LayoutBuilder layout , string path , IBuilder < InjectionRegistry > ? injectors = null , IBuilder < SerializationRegistry > ? formats = null ) where T : new ( )
21
28
{
22
- return layout . Add ( path , ServiceResource . From < T > ( ) ) ;
29
+ return layout . Add ( path , ServiceResource . From < T > ( ) . Configured ( injectors , formats ) ) ;
23
30
}
24
31
25
32
/// <summary>
@@ -28,9 +35,26 @@ public static class Extensions
28
35
/// </summary>
29
36
/// <param name="path">The path the resource should be available at</param>
30
37
/// <param name="instance">The webservice resource instance</param>
31
- public static LayoutBuilder AddService ( this LayoutBuilder layout , string path , object instance )
38
+ /// <param name="injectors">Optionally the injectors to be used by this service</param>
39
+ /// <param name="formats">Optionally the formats to be used by this service</param>
40
+ public static LayoutBuilder AddService ( this LayoutBuilder layout , string path , object instance , IBuilder < InjectionRegistry > ? injectors = null , IBuilder < SerializationRegistry > ? formats = null )
41
+ {
42
+ return layout . Add ( path , ServiceResource . From ( instance ) . Configured ( injectors , formats ) ) ;
43
+ }
44
+
45
+ private static ServiceResourceBuilder Configured ( this ServiceResourceBuilder builder , IBuilder < InjectionRegistry > ? injectors = null , IBuilder < SerializationRegistry > ? formats = null )
32
46
{
33
- return layout . Add ( path , ServiceResource . From ( instance ) ) ;
47
+ if ( injectors != null )
48
+ {
49
+ builder . Injectors ( injectors ) ;
50
+ }
51
+
52
+ if ( formats != null )
53
+ {
54
+ builder . Formats ( formats ) ;
55
+ }
56
+
57
+ return builder ;
34
58
}
35
59
36
60
}
0 commit comments