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