handleContained function

RequestHandler handleContained (
  1. Function handler,
  2. InjectionRequest injection,
  3. [Container container]
)

Handles a request with a DI-enabled handler.

Implementation

RequestHandler handleContained(Function handler, InjectionRequest injection,
    [Container container]) {
  return (RequestContext req, ResponseContext res) async {
    if (injection.parameters.isNotEmpty &&
        injection.parameters.values.any((p) => p.match != null) &&
        !suitableForInjection(req, res, injection)) return Future.value(true);

    List args = [];

    Map<Symbol, dynamic> named = {};

    for (var r in injection.required) {
      args.add(await resolveInjection(r, injection, req, res, true, container));
    }

    for (var entry in injection.named.entries) {
      var name = Symbol(entry.key);
      named[name] = await resolveInjection(
          [entry.key, entry.value], injection, req, res, false, container);
    }

    return Function.apply(handler, args, named);
  };
}