buildControllerMethod static method

RequestHandler buildControllerMethod(
  1. ControllerMethod method
)

Implementation

static RequestHandler buildControllerMethod(ControllerMethod method) {
  final params = method.params;

  return (req, res) {
    final methodName = method.methodName;
    final instance = createNewInstance<HTTPController>(method.controller);
    final mirror = inject.reflect(instance);

    mirror
      ..invokeSetter('request', req)
      ..invokeSetter('response', res);

    late Function() methodCall;

    if (params.isNotEmpty) {
      final args = _resolveControllerMethodArgs(req, method);
      methodCall = () => mirror.invoke(methodName, args);
    } else {
      methodCall = () => mirror.invoke(methodName, []);
    }

    return Future.sync(methodCall);
  };
}