@@ -13,8 +13,6 @@ public sealed partial class ControllerHandler : IHandler, IServiceMethodProvider
1313{
1414 private static readonly Regex HyphenMatcher = CreateHyphenMatcher ( ) ;
1515
16- private MethodCollection ? _methods ;
17-
1816 #region Get-/Setters
1917
2018 private Type Type { get ; }
@@ -23,15 +21,22 @@ public sealed partial class ControllerHandler : IHandler, IServiceMethodProvider
2321
2422 private MethodRegistry Registry { get ; }
2523
24+ private ExecutionSettings ExecutionSettings { get ; }
25+
26+ public SynchronizedMethodCollection Methods { get ; }
27+
2628 #endregion
2729
2830 #region Initialization
2931
30- public ControllerHandler ( Type type , Func < IRequest , ValueTask < object > > instanceProvider , MethodRegistry registry )
32+ public ControllerHandler ( Type type , Func < IRequest , ValueTask < object > > instanceProvider , ExecutionSettings executionSettings , MethodRegistry registry )
3133 {
3234 Type = type ;
3335 InstanceProvider = instanceProvider ;
36+ ExecutionSettings = executionSettings ;
3437 Registry = registry ;
38+
39+ Methods = new SynchronizedMethodCollection ( GetMethodsAsync ) ;
3540 }
3641
3742 #endregion
@@ -40,47 +45,44 @@ public ControllerHandler(Type type, Func<IRequest, ValueTask<object>> instancePr
4045
4146 public ValueTask PrepareAsync ( ) => ValueTask . CompletedTask ;
4247
43- public async ValueTask < IResponse ? > HandleAsync ( IRequest request ) => await ( await GetMethodsAsync ( request ) ) . HandleAsync ( request ) ;
48+ public ValueTask < IResponse ? > HandleAsync ( IRequest request ) => Methods . HandleAsync ( request ) ;
4449
45- public async ValueTask < MethodCollection > GetMethodsAsync ( IRequest request )
50+ private async Task < MethodCollection > GetMethodsAsync ( IRequest request )
4651 {
47- if ( _methods != null ) return _methods ;
48-
4952 var found = new List < MethodHandler > ( ) ;
5053
51-
5254 foreach ( var method in Type . GetMethods ( BindingFlags . Public | BindingFlags . Instance | BindingFlags . DeclaredOnly ) )
5355 {
5456 var annotation = method . GetCustomAttribute < ControllerActionAttribute > ( true ) ?? new MethodAttribute ( ) ;
5557
5658 var arguments = FindPathArguments ( method ) ;
5759
58- var operation = CreateOperation ( request , method , arguments , Registry ) ;
60+ var operation = CreateOperation ( request , method , ExecutionSettings , annotation , arguments , Registry ) ;
5961
60- found . Add ( new MethodHandler ( operation , InstanceProvider , annotation , Registry ) ) ;
62+ found . Add ( new MethodHandler ( operation , InstanceProvider , Registry ) ) ;
6163 }
6264
6365 var result = new MethodCollection ( found ) ;
6466
6567 await result . PrepareAsync ( ) ;
6668
67- return _methods = result ;
69+ return result ;
6870 }
6971
70- private static Operation CreateOperation ( IRequest request , MethodInfo method , List < string > arguments , MethodRegistry registry )
72+ private static Operation CreateOperation ( IRequest request , MethodInfo method , ExecutionSettings executionSettings , IMethodConfiguration configuration , List < string > arguments , MethodRegistry registry )
7173 {
7274 var pathArguments = string . Join ( '/' , arguments . Select ( a => $ ":{ a } ") ) ;
7375
7476 if ( method . Name == "Index" )
7577 {
76- return OperationBuilder . Create ( request , pathArguments . Length > 0 ? $ "/{ pathArguments } /" : null , method , registry , true ) ;
78+ return OperationBuilder . Create ( request , pathArguments . Length > 0 ? $ "/{ pathArguments } /" : null , method , null , executionSettings , configuration , registry , true ) ;
7779 }
7880
7981 var name = HypenCase ( method . Name ) ;
8082
8183 var path = $ "/{ name } ";
8284
83- return OperationBuilder . Create ( request , pathArguments . Length > 0 ? $ "{ path } /{ pathArguments } /" : $ "{ path } /", method , registry , true ) ;
85+ return OperationBuilder . Create ( request , pathArguments . Length > 0 ? $ "{ path } /{ pathArguments } /" : $ "{ path } /", method , null , executionSettings , configuration , registry , true ) ;
8486 }
8587
8688 private static List < string > FindPathArguments ( MethodInfo method )
0 commit comments