diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index d56708ee..f64ab1bf 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,8 +3,22 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -30,8 +44,8 @@
-
-
+
+
@@ -39,50 +53,47 @@
-
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
+
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
@@ -90,6 +101,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -102,9 +155,6 @@
- random_strin
- Angel()
- change
render
god.serialize
dart:mirrors
@@ -132,10 +182,11 @@
lazyQue
injections
singleton(
+ preI
+ );
+ RequestContext req
- useStream
- streaming
!isOpen
'server'
FutureOr
@@ -164,6 +215,8 @@
json.decode
rawRequest.
rawResponse.
+ ));
+ req
C:\Users\thosa\Source\Angel\framework\lib
@@ -187,29 +240,19 @@
@@ -657,21 +710,7 @@
-
-
-
- 1531148520815
-
-
-
- 1531148520815
-
-
- 1531148881567
-
-
-
- 1531148881568
+
1531149542907
@@ -1002,7 +1041,21 @@
1534794944288
-
+
+ 1534795218407
+
+
+
+ 1534795218407
+
+
+ 1534796466854
+
+
+
+ 1534796466854
+
+
@@ -1038,7 +1091,7 @@
-
+
@@ -1058,7 +1111,7 @@
-
+
@@ -1077,6 +1130,7 @@
+
@@ -1087,7 +1141,6 @@
-
@@ -1101,8 +1154,6 @@
-
-
@@ -1126,7 +1177,9 @@
-
+
+
+
@@ -1134,41 +1187,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1176,13 +1194,6 @@
-
-
-
-
-
-
-
@@ -1190,13 +1201,6 @@
-
-
-
-
-
-
-
@@ -1211,28 +1215,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1283,13 +1266,6 @@
-
-
-
-
-
-
-
@@ -1297,13 +1273,6 @@
-
-
-
-
-
-
-
@@ -1314,13 +1283,6 @@
-
-
-
-
-
-
-
@@ -1335,81 +1297,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1417,16 +1304,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -1444,37 +1321,222 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b961440..8df5a275 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -39,4 +39,7 @@ exclusively to close responses.
take routes in the form of `FutureOr myFunc(RequestContext, ResponseContext res)`.
* `@Middleware` now takes an `Iterable` of `RequestHandler`s.
* `@Expose.path` now *must* be a `String`, not just any `Pattern`.
-* `@Expose.middleware` now takes `Iterable`, instead of just `List`.
\ No newline at end of file
+* `@Expose.middleware` now takes `Iterable`, instead of just `List`.
+* `createDynamicHandler` was renamed to `ioc`, and is now used to run IoC-aware handlers in a
+type-safe manner.
+* `RequestContext.params` is now a `Map`, rather than just a `Map`.
\ No newline at end of file
diff --git a/example/main.dart b/example/main.dart
index e1437137..dc7ef909 100644
--- a/example/main.dart
+++ b/example/main.dart
@@ -5,16 +5,28 @@ main() async {
var app = new Angel(reflector: MirrorsReflector());
// Index route. Returns JSON.
- app.get('/', () => 'Welcome to Angel!');
+ app.get('/', (req, res) => res.write('Welcome to Angel!'));
// Accepts a URL like /greet/foo or /greet/bob.
- app.get('/greet/:name', (String name) => 'Hello, $name!');
+ app.get(
+ '/greet/:name',
+ (req, res) {
+ var name = req.params['name'];
+ res.write('Hello, $name!');
+ },
+ );
// Pattern matching - only call this handler if the query value of `name` equals 'emoji'.
- app.get('/greet', (@Query('name', match: 'emoji') String name) => '😇🔥🔥🔥');
+ app.get(
+ '/greet',
+ ioc((@Query('name', match: 'emoji') String name) => '😇🔥🔥🔥'),
+ );
// Handle any other query value of `name`.
- app.get('/greet', (@Query('name') String name) => 'Hello, $name!');
+ app.get(
+ '/greet',
+ ioc((@Query('name') String name) => 'Hello, $name!'),
+ );
// Simple fallback to throw a 404 on unknown paths.
app.use((RequestContext req) async {
diff --git a/lib/src/core/injection.dart b/lib/src/core/injection.dart
index a70ee45f..b6228a27 100644
--- a/lib/src/core/injection.dart
+++ b/lib/src/core/injection.dart
@@ -5,7 +5,7 @@ const List _primitiveTypes = [String, int, num, double, Null];
/// Shortcut for calling [preInject], and then [handleContained].
///
/// Use this to instantly create a request handler for a DI-enabled method.
-RequestHandler createDynamicHandler(Function handler,
+RequestHandler ioc(Function handler,
{Iterable optional: const []}) {
var injection = preInject(handler);
injection.optional.addAll(optional ?? []);
diff --git a/lib/src/core/request_context.dart b/lib/src/core/request_context.dart
index 32e8e2af..a8c4530c 100644
--- a/lib/src/core/request_context.dart
+++ b/lib/src/core/request_context.dart
@@ -65,7 +65,7 @@ abstract class RequestContext {
MediaType get contentType;
/// The URL parameters extracted from the request URI.
- Map params = {};
+ Map params = {};
/// The requested path.
String get path;
diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart
index 0428d222..88d42e65 100644
--- a/lib/src/core/server.dart
+++ b/lib/src/core/server.dart
@@ -162,8 +162,9 @@ class Angel extends Routable {
};
@override
- Route addRoute(String method, String path, Object handler,
- {Iterable middleware: const []}) {
+ Route addRoute(
+ String method, String path, RequestHandler handler,
+ {Iterable middleware: const []}) {
if (_flattened != null) {
logger?.warning(
'WARNING: You added a route ($method $path) to the router, after it had been optimized.');
@@ -175,7 +176,7 @@ class Angel extends Routable {
}
@override
- mount(Pattern path, Router router) {
+ mount(String path, Router router) {
if (_flattened != null) {
logger?.warning(
'WARNING: You added mounted a child router ($path) on the router, after it had been optimized.');
@@ -275,11 +276,6 @@ class Angel extends Routable {
return getHandlerResult(handler.toList(), req, res);
}
- var middleware = (req.app ?? this).findMiddleware(handler);
- if (middleware != null) {
- return getHandlerResult(middleware, req, res);
- }
-
return new Future.value(handler);
}
@@ -298,12 +294,6 @@ class Angel extends Routable {
});
}
- /// Attempts to find a middleware by the given name within this application.
- findMiddleware(key) {
- if (requestMiddleware.containsKey(key)) return requestMiddleware[key];
- return parent != null ? parent.findMiddleware(key) : null;
- }
-
/// Attempts to find a property by the given name within this application.
findProperty(key) {
if (configuration.containsKey(key)) return configuration[key];
@@ -327,7 +317,6 @@ class Angel extends Routable {
}
void _walk(Router router) {
- router.requestMiddleware.forEach((k, v) => _add(v));
router.middleware.forEach(_add);
router.routes.forEach((r) {
r.handlers.forEach(_add);
diff --git a/lib/src/core/service.dart b/lib/src/core/service.dart
index 64e8d942..dfb3d8e9 100644
--- a/lib/src/core/service.dart
+++ b/lib/src/core/service.dart
@@ -160,7 +160,7 @@ class Service extends Routable {
if (before != null) handlers.addAll(before.handlers);
Middleware indexMiddleware = getAnnotation(service.index, Middleware);
- get('/', (RequestContext req, res) {
+ get('/', (req, res) {
return req.parseQuery().then((query) {
return this.index(mergeMap([
{'query': query},
@@ -174,7 +174,7 @@ class Service extends Routable {
..addAll((indexMiddleware == null) ? [] : indexMiddleware.handlers));
Middleware createMiddleware = getAnnotation(service.create, Middleware);
- post('/', (RequestContext req, ResponseContext res) {
+ post('/', (req, ResponseContext res) {
return req.parseQuery().then((query) {
return req.parseBody().then((body) {
return this
@@ -199,7 +199,7 @@ class Service extends Routable {
Middleware readMiddleware = getAnnotation(service.read, Middleware);
- get('/:id', (RequestContext req, res) {
+ get('/:id', (req, res) {
return req.parseQuery().then((query) {
return this.read(
parseId(req.params['id']),
@@ -217,7 +217,7 @@ class Service extends Routable {
Middleware modifyMiddleware = getAnnotation(service.modify, Middleware);
patch(
'/:id',
- (RequestContext req, res) => req.parseBody().then((body) {
+ (req, res) => req.parseBody().then((body) {
return req.parseQuery().then((query) {
return this.modify(
parseId(req.params['id']),
@@ -237,7 +237,7 @@ class Service extends Routable {
Middleware updateMiddleware = getAnnotation(service.update, Middleware);
post(
'/:id',
- (RequestContext req, res) => req.parseBody().then((body) {
+ (req, res) => req.parseBody().then((body) {
return req.parseQuery().then((query) {
return this.update(
parseId(req.params['id']),
@@ -255,7 +255,7 @@ class Service extends Routable {
(updateMiddleware == null) ? [] : updateMiddleware.handlers));
put(
'/:id',
- (RequestContext req, res) => req.parseBody().then((body) {
+ (req, res) => req.parseBody().then((body) {
return req.parseQuery().then((query) {
return this.update(
parseId(req.params['id']),
@@ -273,7 +273,7 @@ class Service extends Routable {
(updateMiddleware == null) ? [] : updateMiddleware.handlers));
Middleware removeMiddleware = getAnnotation(service.remove, Middleware);
- delete('/', (RequestContext req, res) {
+ delete('/', (req, res) {
return req.parseQuery().then((query) {
return this.remove(
null,
@@ -288,7 +288,7 @@ class Service extends Routable {
..addAll(handlers)
..addAll(
(removeMiddleware == null) ? [] : removeMiddleware.handlers));
- delete('/:id', (RequestContext req, res) {
+ delete('/:id', (req, res) {
return req.parseQuery().then((query) {
return this.remove(
parseId(req.params['id']),
@@ -305,8 +305,8 @@ class Service extends Routable {
(removeMiddleware == null) ? [] : removeMiddleware.handlers));
// REST compliance
- put('/', () => throw new AngelHttpException.notFound());
- patch('/', () => throw new AngelHttpException.notFound());
+ put('/', (req, res) => throw new AngelHttpException.notFound());
+ patch('/', (req, res) => throw new AngelHttpException.notFound());
}
/// Invoked when this service is wrapped within a [HookedService].
diff --git a/lib/src/http/controller.dart b/lib/src/http/controller.dart
index 1b81102e..d910cb9a 100644
--- a/lib/src/http/controller.dart
+++ b/lib/src/http/controller.dart
@@ -2,8 +2,10 @@ library angel_framework.http.controller;
import 'dart:async';
import 'dart:mirrors';
+
import 'package:angel_route/angel_route.dart';
import 'package:meta/meta.dart';
+
import '../core/core.dart';
/// Supports grouping routes with shared functionality.
@@ -19,7 +21,7 @@ class Controller {
final bool injectSingleton;
/// Middleware to run before all handlers in this class.
- List middleware = [];
+ List middleware = [];
/// A mapping of route paths to routes, produced from the [Expose] annotations on this class.
Map routeMappings = {};
@@ -30,7 +32,9 @@ class Controller {
Future configureServer(Angel app) {
_app = app;
- if (injectSingleton != false) _app.container.singleton(this);
+ if (injectSingleton != false) {
+ _app.container.registerSingleton(this, as: runtimeType);
+ }
// Load global expose decl
ClassMirror classMirror = reflectClass(this.runtimeType);
@@ -52,7 +56,9 @@ class Controller {
// Pre-reflect methods
InstanceMirror instanceMirror = reflect(this);
- final handlers = []..addAll(exposeDecl.middleware)..addAll(middleware);
+ final handlers = []
+ ..addAll(exposeDecl.middleware)
+ ..addAll(middleware);
final routeBuilder = _routeBuilder(instanceMirror, routable, handlers);
classMirror.instanceMembers.forEach(routeBuilder);
configureRoutes(routable);
@@ -60,7 +66,9 @@ class Controller {
}
void Function(Symbol, MethodMirror) _routeBuilder(
- InstanceMirror instanceMirror, Routable routable, Iterable handlers) {
+ InstanceMirror instanceMirror,
+ Routable routable,
+ Iterable handlers) {
return (Symbol methodName, MethodMirror method) {
if (method.isRegularMethod &&
methodName != #toString &&
@@ -76,7 +84,9 @@ class Controller {
var reflectedMethod =
instanceMirror.getField(methodName).reflectee as Function;
- var middleware = []..addAll(handlers)..addAll(exposeDecl.middleware);
+ var middleware = []
+ ..addAll(handlers)
+ ..addAll(exposeDecl.middleware);
String name = exposeDecl.as?.isNotEmpty == true
? exposeDecl.as
: MirrorSystem.getName(methodName);
diff --git a/performance/hello/main.dart b/performance/hello/main.dart
index ca1e34f5..717cc548 100644
--- a/performance/hello/main.dart
+++ b/performance/hello/main.dart
@@ -26,7 +26,7 @@ void start(int id) {
var app = new Angel(reflector: MirrorsReflector());
var http = new AngelHttp.custom(app, startShared, useZone: false);
- app.get('/', (ResponseContext res) => res.write('Hello, world!'));
+ app.get('/', (req, res) => res.write('Hello, world!'));
var oldHandler = app.errorHandler;
app.errorHandler = (e, req, res) {
diff --git a/test/controller_test.dart b/test/controller_test.dart
index ba6f450e..35604b07 100644
--- a/test/controller_test.dart
+++ b/test/controller_test.dart
@@ -1,20 +1,20 @@
import 'dart:async';
+import 'dart:convert';
import 'dart:io';
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
-import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
import 'common.dart';
-@Expose("/todos", middleware: ["foo"])
+@Expose("/todos", middleware: [foo])
class TodoController extends Controller {
List todos = [new Todo(text: "Hello", over: "world")];
- @Expose("/:id", middleware: ["bar"])
+ @Expose("/:id", middleware: [bar])
Future fetchTodo(
String id, RequestContext req, ResponseContext res) async {
expect(req, isNotNull);
@@ -37,6 +37,14 @@ class NamedController extends Controller {
optional() => 2;
}
+void foo(RequestContext req, ResponseContext res) {
+ res.write("Hello, ");
+}
+
+void bar(RequestContext req, ResponseContext res) {
+ res.write("world!");
+}
+
main() {
Angel app;
TodoController ctrl;
@@ -46,17 +54,9 @@ main() {
setUp(() async {
app = new Angel(reflector: MirrorsReflector());
- app.requestMiddleware["foo"] = (req, res) async {
- res.write("Hello, ");
- return true;
- };
- app.requestMiddleware["bar"] = (req, res) async {
- res.write("world!");
- return true;
- };
app.get(
"/redirect",
- (req, ResponseContext res) async =>
+ (req, res) async =>
res.redirectToAction("TodoController@foo", {"foo": "world"}));
await app.configure((ctrl = new TodoController()).configureServer);
@@ -91,7 +91,7 @@ main() {
var app = new Angel(reflector: MirrorsReflector());
app.get(
'/foo',
- createDynamicHandler(({String bar}) {
+ ioc(({String bar}) {
return 2;
}, optional: ['bar']));
var rq = new MockHttpRequest('GET', new Uri(path: 'foo'));
diff --git a/test/di_test.dart b/test/di_test.dart
index 46dd25f6..53bd5493 100644
--- a/test/di_test.dart
+++ b/test/di_test.dart
@@ -1,9 +1,11 @@
+import 'dart:convert';
import 'dart:io';
+
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
-import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
+
import 'common.dart';
final String TEXT = "make your bed";
@@ -20,11 +22,13 @@ main() {
client = new http.Client();
// Inject some todos
- app.container.singleton(new Todo(text: TEXT, over: OVER));
+ app.container.registerSingleton(new Todo(text: TEXT, over: OVER));
- app.get("/errands", (Todo singleton) => singleton);
- app.get("/errands3",
- ({Errand singleton, Todo foo, RequestContext req}) => singleton.text);
+ app.get("/errands", ioc((Todo singleton) => singleton));
+ app.get(
+ "/errands3",
+ ioc(({Errand singleton, Todo foo, RequestContext req}) =>
+ singleton.text));
await app.configure(new SingletonController().configureServer);
await app.configure(new ErrandController().configureServer);
diff --git a/test/encoders_buffer_test.dart b/test/encoders_buffer_test.dart
index da172cc0..05d7070e 100644
--- a/test/encoders_buffer_test.dart
+++ b/test/encoders_buffer_test.dart
@@ -26,7 +26,7 @@ main() {
},
);
- app.get('/hello', (res) {
+ app.get('/hello', (req, res) {
res.write('Hello, world!');
});
});
diff --git a/test/parameter_meta_test.dart b/test/parameter_meta_test.dart
index 399488e4..2a767f56 100644
--- a/test/parameter_meta_test.dart
+++ b/test/parameter_meta_test.dart
@@ -1,7 +1,8 @@
import 'dart:async';
-import 'dart:io';
-import 'package:angel_container/mirrors.dart';
import 'dart:convert';
+import 'dart:io';
+
+import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
@@ -31,33 +32,33 @@ parameterMetaTests() {
app = new Angel(reflector: MirrorsReflector());
http = new AngelHttp(app);
- app.get('/cookie', (@CookieValue('token') String jwt) {
+ app.get('/cookie', ioc((@CookieValue('token') String jwt) {
return jwt;
- });
+ }));
- app.get('/header', (@Header('x-foo') String header) {
+ app.get('/header', ioc((@Header('x-foo') String header) {
return header;
- });
+ }));
- app.get('/query', (@Query('q') String query) {
+ app.get('/query', ioc((@Query('q') String query) {
return query;
- });
+ }));
- app.get('/session', (@Session('foo') String foo) {
+ app.get('/session', ioc((@Session('foo') String foo) {
return foo;
- });
+ }));
- app.get('/match', (@Query('mode', match: 'pos') String mode) {
+ app.get('/match', ioc((@Query('mode', match: 'pos') String mode) {
return 'YES $mode';
- });
+ }));
- app.get('/match', (@Query('mode', match: 'neg') String mode) {
+ app.get('/match', ioc((@Query('mode', match: 'neg') String mode) {
return 'NO $mode';
- });
+ }));
- app.get('/match', (@Query('mode') String mode) {
+ app.get('/match', ioc((@Query('mode') String mode) {
return 'DEFAULT $mode';
- });
+ }));
/*app.logger = new Logger('parameter_meta_test')
..onRecord.listen((rec) {
diff --git a/test/precontained_test.dart b/test/precontained_test.dart
index afb86952..3488ab8d 100644
--- a/test/precontained_test.dart
+++ b/test/precontained_test.dart
@@ -1,6 +1,7 @@
+import 'dart:convert';
+
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
-import 'dart:convert';
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
@@ -8,7 +9,7 @@ main() {
test('preinjects functions', () async {
var app = new Angel(reflector: MirrorsReflector())
..configuration['foo'] = 'bar'
- ..get('/foo', echoAppFoo);
+ ..get('/foo', ioc(echoAppFoo));
app.optimizeForProduction(force: true);
print(app.preContained);
expect(app.preContained, contains(echoAppFoo));
diff --git a/test/primitives_test.dart b/test/primitives_test.dart
index a35caa9f..25a7ffde 100644
--- a/test/primitives_test.dart
+++ b/test/primitives_test.dart
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io' show stderr;
+
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
import 'package:mock_request/mock_request.dart';
@@ -10,22 +11,23 @@ main() {
AngelHttp http;
setUp(() {
- app = new Angel(reflector: MirrorsReflector())..inject('global', 305); // Pitbull!
+ app = new Angel(reflector: MirrorsReflector())
+ ..inject('global', 305); // Pitbull!
http = new AngelHttp(app);
- app.get('/string/:string', (String string) => string);
+ app.get('/string/:string', ioc((String string) => string));
app.get(
'/num/parsed/:num',
waterfall([
- (RequestContext req) {
+ (req, res) {
req.params['n'] = num.parse(req.params['num'].toString());
return true;
},
- (num n) => n,
+ ioc((num n) => n),
]));
- app.get('/num/global', (num global) => global);
+ app.get('/num/global', ioc((num global) => global));
app.errorHandler = (e, req, res) {
stderr..writeln(e.error)..writeln(e.stackTrace);
diff --git a/test/repeat_request_test.dart b/test/repeat_request_test.dart
index 0b526394..94d1e8a9 100644
--- a/test/repeat_request_test.dart
+++ b/test/repeat_request_test.dart
@@ -1,7 +1,8 @@
import 'dart:async';
+import 'dart:convert';
+
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
-import 'dart:convert';
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
@@ -11,7 +12,8 @@ main() {
}
test('can request the same url twice', () async {
- var app = new Angel(reflector: MirrorsReflector())..get('/test/:id', (id) => 'Hello $id');
+ var app = new Angel(reflector: MirrorsReflector())
+ ..get('/test/:id', ioc((id) => 'Hello $id'));
var rq1 = mk(1), rq2 = mk(2), rq3 = mk(1);
await Future.wait([rq1, rq2, rq3].map(new AngelHttp(app).handleRequest));
var body1 = await rq1.response.transform(utf8.decoder).join(),
diff --git a/test/routing_test.dart b/test/routing_test.dart
index c79cc763..59104d26 100644
--- a/test/routing_test.dart
+++ b/test/routing_test.dart
@@ -69,8 +69,9 @@ main() {
app.use('/nes', nested);
app.get('/meta', testMiddlewareMetadata);
- app.get('/intercepted', 'This should not be shown', middleware: ['interceptor']);
- app.get('/hello', 'world');
+ app.get('/intercepted', (req, res) => 'This should not be shown',
+ middleware: [interceptor]);
+ app.get('/hello', (req, res) => 'world');
app.get('/name/:first/last/:last', (req, res) => req.params);
app.post('/lambda', (RequestContext req, res) => req.parseBody());
app.use('/todos/:id', todos);
@@ -86,8 +87,8 @@ main() {
return "Logged";
});
- app.get('/method', () => 'Only GET');
- app.post('/method', () => 'Only POST');
+ app.get('/method', (req, res) => 'Only GET');
+ app.post('/method', (req, res) => 'Only POST');
app.use('/query', new QueryService());
@@ -98,7 +99,7 @@ main() {
}
app.chain([write('a')]).chain([write('b'), write('c')]).get(
- '/chained', () => false);
+ '/chained', (req, res) => false);
app.use('MJ');
diff --git a/test/serialize_test.dart b/test/serialize_test.dart
index 6a601011..c8776e4d 100644
--- a/test/serialize_test.dart
+++ b/test/serialize_test.dart
@@ -14,8 +14,8 @@ main() {
setUp(() async {
app = new Angel(reflector: MirrorsReflector())
- ..get('/foo', () => {'hello': 'world'})
- ..get('/bar', (req, ResponseContext res) async {
+ ..get('/foo', ioc(() => {'hello': 'world'}))
+ ..get('/bar', (req, res) async {
res.contentType = new MediaType('text', 'html');
await res.serialize({'hello': 'world'});
});
diff --git a/test/server_test.dart b/test/server_test.dart
index 3f6531cb..a3d81493 100644
--- a/test/server_test.dart
+++ b/test/server_test.dart
@@ -1,8 +1,9 @@
import 'dart:async';
+import 'dart:convert';
import 'dart:io';
+
import 'package:angel_container/mirrors.dart';
import 'package:angel_framework/angel_framework.dart';
-import 'dart:convert';
import 'package:matcher/matcher.dart';
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
@@ -12,7 +13,8 @@ final Uri $foo = Uri.parse('http://localhost:3000/foo');
/// Additional tests to improve coverage of server.dart
main() {
group('scoping', () {
- var parent = new Angel(reflector: MirrorsReflector())..configuration['two'] = 2;
+ var parent = new Angel(reflector: MirrorsReflector())
+ ..configuration['two'] = 2;
var child = new Angel(reflector: MirrorsReflector());
parent.use('/child', child);
@@ -70,10 +72,11 @@ main() {
});
test('warning when adding routes to flattened router', () {
- var app = new Angel(reflector: MirrorsReflector())..optimizeForProduction(force: true);
+ var app = new Angel(reflector: MirrorsReflector())
+ ..optimizeForProduction(force: true);
app.dumpTree();
- app.get('/', () => 2);
- app.mount('/foo', new Router()..get('/', 3));
+ app.get('/', (req, res) => 2);
+ app.mount('/foo', new Router()..get('/', (req, res) => 3));
});
test('services close on close call', () async {
@@ -88,7 +91,7 @@ main() {
test('global injection added to injection map', () async {
var app = new Angel(reflector: MirrorsReflector())..inject('a', 'b');
var http = new AngelHttp(app);
- app.get('/', (String a) => a);
+ app.get('/', ioc((String a) => a));
var rq = new MockHttpRequest('GET', Uri.parse('/'))..close();
await http.handleRequest(rq);
var body = await rq.response.transform(utf8.decoder).join();
@@ -153,8 +156,8 @@ main() {
setUp(() async {
app = new Angel(reflector: MirrorsReflector());
- app.get('/wtf', () => throw new AngelHttpException.forbidden());
- app.get('/wtf2', () => throw new AngelHttpException.forbidden());
+ app.get('/wtf', (req, res) => throw new AngelHttpException.forbidden());
+ app.get('/wtf2', (req, res) => throw new AngelHttpException.forbidden());
http = new AngelHttp(app);
await http.startServer('127.0.0.1', 0);