From 6d2be105360a1a70ee71ae80650674010cb3c07e Mon Sep 17 00:00:00 2001 From: thomashii Date: Sat, 19 Feb 2022 20:24:34 +0800 Subject: [PATCH] Removed dependency on mirror --- .../container/angel_container_generator/pubspec.yaml | 9 ++++++--- packages/framework/lib/src/core/injection.dart | 8 +++++--- packages/framework/lib/src/core/server.dart | 9 ++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/container/angel_container_generator/pubspec.yaml b/packages/container/angel_container_generator/pubspec.yaml index 831b4be5..c22acfc7 100644 --- a/packages/container/angel_container_generator/pubspec.yaml +++ b/packages/container/angel_container_generator/pubspec.yaml @@ -1,15 +1,18 @@ name: angel3_container_generator -version: 3.0.1 +version: 6.0.0 description: Codegen support for using pkg:reflectable with pkg:angel3_container. homepage: https://angel3-framework.web.app/ repository: https://github.com/dukefirehawk/angel/tree/master/packages/container/angel_container_generator environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.15.0 <3.0.0' dependencies: - angel3_container: ^3.1.0 + angel3_container: ^6.0.0 reflectable: ^3.0.4 dev_dependencies: build_runner: ^2.1.2 build_test: ^2.1.3 test: ^1.17.5 lints: ^1.0.1 +dependency_overrides: + angel3_container: + path: ../angel_container diff --git a/packages/framework/lib/src/core/injection.dart b/packages/framework/lib/src/core/injection.dart index 08563d0f..1d81a188 100644 --- a/packages/framework/lib/src/core/injection.dart +++ b/packages/framework/lib/src/core/injection.dart @@ -101,7 +101,9 @@ RequestHandler handleContained(Function handler, InjectionRequest injection, 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); + !suitableForInjection(req, res, injection)) { + return Future.value(true); + } var args = []; @@ -167,10 +169,10 @@ InjectionRequest preInject(Function handler, Reflector reflector) { var name = parameter.name; var type = parameter.type.reflectedType; - var _Parameter = reflector.reflectType(Parameter); + var _parameter = reflector.reflectType(Parameter); var p = parameter.annotations - .firstWhereOrNull((m) => m.type.isAssignableTo(_Parameter)) + .firstWhereOrNull((m) => m.type.isAssignableTo(_parameter)) ?.reflectee as Parameter?; //print(p); if (p != null) { diff --git a/packages/framework/lib/src/core/server.dart b/packages/framework/lib/src/core/server.dart index 089bb01c..45d6f44f 100644 --- a/packages/framework/lib/src/core/server.dart +++ b/packages/framework/lib/src/core/server.dart @@ -4,7 +4,6 @@ import 'dart:async'; import 'dart:collection' show HashMap; import 'dart:convert'; import 'package:angel3_container/angel3_container.dart'; -import 'package:angel3_container/mirrors.dart'; import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:angel3_route/angel3_route.dart'; import 'package:belatuk_combinator/belatuk_combinator.dart'; @@ -322,7 +321,7 @@ class Angel extends Routable { /// the execution will be faster, as the injection requirements were stored beforehand. Future runContained(Function handler, RequestContext req, ResponseContext res, [Container? container]) { - container ??= Container(MirrorsReflector()); + container ??= Container(EmptyReflector()); return Future.sync(() { if (_preContained.containsKey(handler)) { return handleContained(handler, _preContained[handler]!, container)( @@ -337,7 +336,11 @@ class Angel extends Routable { Future runReflected(Function handler, RequestContext req, ResponseContext res, [Container? container]) { container ??= - req.container ?? res.app?.container ?? Container(ThrowingReflector()); + req.container ?? res.app?.container ?? Container(EmptyReflector()); + + if (container.reflector is EmptyReflector) { + throw ArgumentError("No `reflector` passed"); + } var h = handleContained( handler, _preContained[handler] = preInject(handler, container.reflector),