diff --git a/.idea/libraries/Dart_Packages.xml b/.idea/libraries/Dart_Packages.xml
index db6079ec..b8dfae30 100644
--- a/.idea/libraries/Dart_Packages.xml
+++ b/.idea/libraries/Dart_Packages.xml
@@ -12,7 +12,7 @@
-
+
@@ -454,7 +454,7 @@
-
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 6c8be27b..7de0fedd 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,15 +4,12 @@
-
-
+
-
+
+
-
-
-
-
+
@@ -62,17 +59,59 @@
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -80,8 +119,8 @@
-
-
+
+
@@ -89,6 +128,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -128,9 +179,9 @@
stopw
release
handleRe
- mirrors
get container
Parameter
+ mirrors
FutureOr
@@ -217,26 +268,26 @@
-
-
-
-
-
+
+
+
+
+
@@ -256,8 +307,8 @@
-
-
+
+
@@ -314,6 +365,11 @@
+
+
+
+
+
@@ -362,7 +418,7 @@
-
+
@@ -662,14 +718,7 @@
-
-
-
- 1534547132671
-
-
-
- 1534547132671
+
1534692805087
@@ -1007,19 +1056,17 @@
1534816646962
-
+
+ 1534819472503
+
+
+
+ 1534819472503
+
+
-
-
-
-
-
-
-
-
-
@@ -1041,9 +1088,18 @@
+
+
+
+
+
+
+
+
+
-
+
@@ -1055,7 +1111,7 @@
-
+
@@ -1079,9 +1135,9 @@
-
+
-
+
@@ -1106,7 +1162,6 @@
-
@@ -1131,7 +1186,8 @@
-
+
+
@@ -1139,30 +1195,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1307,16 +1339,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1324,16 +1346,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1358,16 +1370,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1429,13 +1431,6 @@
-
-
-
-
-
-
-
@@ -1443,16 +1438,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1488,13 +1473,6 @@
-
-
-
-
-
-
-
@@ -1502,23 +1480,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1529,10 +1490,105 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d5982410..26d2c047 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,4 +61,7 @@ as in many cases it is unnecessary and slows down response time.
* Removed the now-obsolete `ResponseContext.willCloseItself`.
* Removed `ResponseContext.dispose`.
* Removed the now-obsolete `ResponseContext.end`.
-* Removed the now-obsolete `ResponseContext.releaseCorrespondingRequest`.
\ No newline at end of file
+* Removed the now-obsolete `ResponseContext.releaseCorrespondingRequest`.
+* `preInject` now takes a `Reflector` as its second argument.
+* `Angel.reflector` defaults to `const EmptyReflector()`, disabling
+reflection out-of-the-box.
\ No newline at end of file
diff --git a/lib/src/core/injection.dart b/lib/src/core/injection.dart
index 6e56635a..ff086ee6 100644
--- a/lib/src/core/injection.dart
+++ b/lib/src/core/injection.dart
@@ -8,10 +8,16 @@ const List _primitiveTypes = [String, int, num, double, Null];
///
/// Calling [ioc] also auto-serializes the result of a [handler].
RequestHandler ioc(Function handler, {Iterable optional: const []}) {
- var injection = preInject(handler);
- injection.optional.addAll(optional ?? []);
- var contained = handleContained(handler, injection);
+ InjectionRequest injection;
+ RequestHandler contained;
+
return (req, res) {
+ if (injection == null) {
+ injection = preInject(handler, req.app.container.reflector);
+ injection.optional.addAll(optional ?? []);
+ contained = handleContained(handler, injection);
+ }
+
return req.app.executeHandler(contained, req, res);
};
}
@@ -127,22 +133,22 @@ class InjectionRequest {
parameters = {};
}
-final TypeMirror _Parameter = reflectType(Parameter);
-
/// Predetermines what needs to be injected for a handler to run.
-InjectionRequest preInject(Function handler) {
+InjectionRequest preInject(Function handler, Reflector reflector) {
var injection = new InjectionRequest();
- ClosureMirror closureMirror = reflect(handler);
+ var closureMirror = reflector.reflectFunction(handler);
- if (closureMirror.function.parameters.isEmpty) return injection;
+ if (closureMirror.parameters.isEmpty) return injection;
// Load parameters
- for (var parameter in closureMirror.function.parameters) {
- var name = MirrorSystem.getName(parameter.simpleName);
+ for (var parameter in closureMirror.parameters) {
+ var name = parameter.name;
var type = parameter.type.reflectedType;
- var p = parameter.metadata
+ var _Parameter = reflector.reflectType(Parameter);
+
+ var p = parameter.annotations
.firstWhere((m) => m.type.isAssignableTo(_Parameter),
orElse: () => null)
?.reflectee as Parameter;
@@ -160,7 +166,7 @@ InjectionRequest preInject(Function handler) {
}
if (!parameter.isNamed) {
- if (parameter.isOptional) injection.optional.add(name);
+ if (!parameter.isRequired) injection.optional.add(name);
if (type == RequestContext || type == ResponseContext) {
injection.required.add(type);
diff --git a/lib/src/core/request_context.dart b/lib/src/core/request_context.dart
index da47bef1..deeec10e 100644
--- a/lib/src/core/request_context.dart
+++ b/lib/src/core/request_context.dart
@@ -2,7 +2,7 @@ library angel_framework.http.request_context;
import 'dart:async';
import 'dart:io' show Cookie, HttpHeaders, HttpSession, InternetAddress;
-import 'dart:mirrors';
+//import 'dart:mirrors';
import 'package:angel_container/angel_container.dart';
import 'package:body_parser/body_parser.dart';
diff --git a/lib/src/core/response_context.dart b/lib/src/core/response_context.dart
index 0964db40..214637b7 100644
--- a/lib/src/core/response_context.dart
+++ b/lib/src/core/response_context.dart
@@ -242,7 +242,7 @@ abstract class ResponseContext
"Controller '${split[0]}' does not contain any action named '${split[1]}'");
final head =
- controller.findExpose().path.toString().replaceAll(_straySlashes, '');
+ controller.findExpose(app.container.reflector).path.toString().replaceAll(_straySlashes, '');
final tail = matched
.makeUri(params.keys.fold