Make reflector a named parameter
This commit is contained in:
parent
4fce6594e2
commit
1d8f06b54c
25 changed files with 44 additions and 43 deletions
|
@ -12,7 +12,7 @@ To build real-world applications, please see the [homepage](https://angel-dart.g
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
main() async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
|
||||
// Index route. Returns JSON.
|
||||
app.get('/', () => 'Welcome to Angel!');
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:angel_framework/angel_framework.dart';
|
|||
import 'package:logging/logging.dart';
|
||||
|
||||
main() async {
|
||||
var app = new Angel(MirrorsReflector())
|
||||
var app = new Angel(reflector: MirrorsReflector())
|
||||
..lazyParseBodies = true
|
||||
..logger = (new Logger('angel')..onRecord.listen(print))
|
||||
..encoders.addAll({'gzip': gzip.encoder});
|
||||
|
|
|
@ -29,7 +29,7 @@ main() async {
|
|||
}
|
||||
|
||||
serverMain(_) async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp.custom(app, startShared); // Run a cluster
|
||||
|
||||
app.get('/', {
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'package:angel_container/mirrors.dart';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
main() async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
|
||||
// Index route. Returns JSON.
|
||||
app.get('/', () => 'Welcome to Angel!');
|
||||
|
|
|
@ -7,7 +7,7 @@ import 'package:logging/logging.dart';
|
|||
import 'package:path/path.dart' as p;
|
||||
|
||||
main() async {
|
||||
var app = new Angel(MirrorsReflector())
|
||||
var app = new Angel(reflector: MirrorsReflector())
|
||||
..lazyParseBodies = true
|
||||
..logger = (new Logger('angel')..onRecord.listen(print))
|
||||
..encoders.addAll({'gzip': gzip.encoder});
|
||||
|
|
|
@ -2,7 +2,7 @@ import 'package:angel_container/mirrors.dart';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
|
||||
main() async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
|
||||
app.viewGenerator = (name, [data]) async =>
|
||||
'View generator invoked with name $name and data: $data';
|
||||
|
|
|
@ -11,6 +11,7 @@ import 'package:angel_http_exception/angel_http_exception.dart';
|
|||
import 'package:angel_route/angel_route.dart';
|
||||
import 'package:combinator/combinator.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
import '../http/http.dart';
|
||||
|
@ -484,7 +485,7 @@ class Angel extends AngelBase {
|
|||
}
|
||||
|
||||
/// Default constructor. ;)
|
||||
Angel(Reflector reflector) : super(reflector) {
|
||||
Angel({@required Reflector reflector}) : super(reflector) {
|
||||
bootstrapContainer();
|
||||
// ignore: deprecated_member_use
|
||||
createZoneForRequest = defaultZoneCreator;
|
||||
|
@ -509,14 +510,14 @@ class Angel extends AngelBase {
|
|||
@deprecated
|
||||
factory Angel.custom(
|
||||
Future<HttpServer> Function(dynamic, int) serverGenerator) {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
return app.._http = new AngelHttp.custom(app, serverGenerator);
|
||||
}
|
||||
|
||||
/// Use the serving methods in [AngelHttp] instead.
|
||||
@deprecated
|
||||
factory Angel.fromSecurityContext(SecurityContext context) {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
|
||||
app._http = new AngelHttp.custom(app, (address, int port) {
|
||||
return HttpServer.bindSecure(address, port, context);
|
||||
|
@ -529,7 +530,7 @@ class Angel extends AngelBase {
|
|||
@deprecated
|
||||
factory Angel.secure(String certificateChainPath, String serverKeyPath,
|
||||
{String password}) {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
return app
|
||||
.._http = new AngelHttp.secure(app, certificateChainPath, serverKeyPath,
|
||||
password: password);
|
||||
|
|
|
@ -23,7 +23,7 @@ main() async {
|
|||
}
|
||||
|
||||
void start(int id) {
|
||||
var app = new Angel(MirrorsReflector())..lazyParseBodies = true;
|
||||
var app = new Angel(reflector: MirrorsReflector())..lazyParseBodies = true;
|
||||
var http = new AngelHttp.custom(app, startShared, useZone: false);
|
||||
|
||||
app.get('/', (ResponseContext res) => res.write('Hello, world!'));
|
||||
|
|
|
@ -61,7 +61,7 @@ Future<RequestContext> acceptContentTypes(
|
|||
var rq = new MockHttpRequest('GET', ENDPOINT);
|
||||
rq.headers.set('accept', headerString);
|
||||
rq.close();
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp(app);
|
||||
return http.createRequestContext(rq);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ main() {
|
|||
String url;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
app.requestMiddleware["foo"] = (req, res) async {
|
||||
res.write("Hello, ");
|
||||
return true;
|
||||
|
@ -77,7 +77,7 @@ main() {
|
|||
|
||||
test('require expose', () async {
|
||||
try {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
await app.configure(new NoExposeController().configureServer);
|
||||
throw 'Should require @Expose';
|
||||
} on Exception {
|
||||
|
@ -86,7 +86,7 @@ main() {
|
|||
});
|
||||
|
||||
test('create dynamic handler', () async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
app.get(
|
||||
'/foo',
|
||||
createDynamicHandler(({String bar}) {
|
||||
|
@ -99,7 +99,7 @@ main() {
|
|||
});
|
||||
|
||||
test('optional name', () async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
await app.configure(new NamedController().configureServer);
|
||||
expect(app.controllers['foo'], const IsInstanceOf<NamedController>());
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ main() {
|
|||
String url;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
client = new http.Client();
|
||||
|
||||
// Inject some todos
|
||||
|
|
|
@ -18,7 +18,7 @@ main() {
|
|||
Angel app;
|
||||
|
||||
setUp(() {
|
||||
app = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
app.injectEncoders(
|
||||
{
|
||||
'deflate': zlib.encoder,
|
||||
|
|
|
@ -25,7 +25,7 @@ main() {
|
|||
|
||||
Future<RequestContext> makeRequest(String path) {
|
||||
var rq = new MockHttpRequest('GET', ENDPOINT.replace(path: path))..close();
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp(app);
|
||||
return http.createRequestContext(rq);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ main() {
|
|||
String url;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector())
|
||||
app = new Angel(reflector: MirrorsReflector())
|
||||
..post('/foo', () => {'hello': 'world'})
|
||||
..all('*', () => throw new AngelHttpException.notFound());
|
||||
client = new http.Client();
|
||||
|
|
|
@ -19,7 +19,7 @@ main() {
|
|||
HookedService Todos;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
client = new http.Client();
|
||||
app.use('/todos', new MapService());
|
||||
app.use('/books', new BookService());
|
||||
|
|
|
@ -28,7 +28,7 @@ parameterMetaTests() {
|
|||
AngelHttp http;
|
||||
|
||||
setUp(() {
|
||||
app = new Angel(MirrorsReflector())..lazyParseBodies = true;
|
||||
app = new Angel(reflector: MirrorsReflector())..lazyParseBodies = true;
|
||||
http = new AngelHttp(app);
|
||||
|
||||
app.get('/cookie', (@CookieValue('token') String jwt) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:test/test.dart';
|
|||
|
||||
main() {
|
||||
test('preinjects functions', () async {
|
||||
var app = new Angel(MirrorsReflector())
|
||||
var app = new Angel(reflector: MirrorsReflector())
|
||||
..configuration['foo'] = 'bar'
|
||||
..get('/foo', echoAppFoo);
|
||||
app.optimizeForProduction(force: true);
|
||||
|
|
|
@ -10,7 +10,7 @@ main() {
|
|||
AngelHttp http;
|
||||
|
||||
setUp(() {
|
||||
app = new Angel(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);
|
||||
|
|
|
@ -11,7 +11,7 @@ main() {
|
|||
}
|
||||
|
||||
test('can request the same url twice', () async {
|
||||
var app = new Angel(MirrorsReflector())..get('/test/:id', (id) => 'Hello $id');
|
||||
var app = new Angel(reflector: MirrorsReflector())..get('/test/:id', (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(),
|
||||
|
|
|
@ -28,9 +28,9 @@ main() {
|
|||
http.Client client;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector());
|
||||
nested = new Angel(MirrorsReflector());
|
||||
todos = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
nested = new Angel(reflector: MirrorsReflector());
|
||||
todos = new Angel(reflector: MirrorsReflector());
|
||||
|
||||
// Lazy-parse in production
|
||||
[app, nested, todos].forEach((Angel app) {
|
||||
|
|
|
@ -13,7 +13,7 @@ main() {
|
|||
String url;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector())
|
||||
app = new Angel(reflector: MirrorsReflector())
|
||||
..get('/foo', () => {'hello': 'world'})
|
||||
..get('/bar', (req, ResponseContext res) async {
|
||||
res.contentType = new MediaType('text', 'html');
|
||||
|
|
|
@ -12,8 +12,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(MirrorsReflector())..configuration['two'] = 2;
|
||||
var child = new Angel(MirrorsReflector());
|
||||
var parent = new Angel(reflector: MirrorsReflector())..configuration['two'] = 2;
|
||||
var child = new Angel(reflector: MirrorsReflector());
|
||||
parent.use('/child', child);
|
||||
|
||||
test('sets children', () {
|
||||
|
@ -30,13 +30,13 @@ main() {
|
|||
});
|
||||
|
||||
test('custom server generator', () {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp.custom(app, HttpServer.bind);
|
||||
expect(http.serverGenerator, HttpServer.bind);
|
||||
});
|
||||
|
||||
test('default error handler', () async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp(app);
|
||||
var rq = new MockHttpRequest('GET', $foo);
|
||||
rq.close();
|
||||
|
@ -59,7 +59,7 @@ main() {
|
|||
});
|
||||
|
||||
test('plug-ins run on startup', () async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
app.startupHooks.add((app) => app.configuration['two'] = 2);
|
||||
|
||||
var http = new AngelHttp(app);
|
||||
|
@ -70,14 +70,14 @@ main() {
|
|||
});
|
||||
|
||||
test('warning when adding routes to flattened router', () {
|
||||
var app = new Angel(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));
|
||||
});
|
||||
|
||||
test('services close on close call', () async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var svc = new CustomCloseService();
|
||||
expect(svc.value, 2);
|
||||
app.use('/', svc);
|
||||
|
@ -86,7 +86,7 @@ main() {
|
|||
});
|
||||
|
||||
test('global injection added to injection map', () async {
|
||||
var app = new Angel(MirrorsReflector())..inject('a', 'b');
|
||||
var app = new Angel(reflector: MirrorsReflector())..inject('a', 'b');
|
||||
var http = new AngelHttp(app);
|
||||
app.get('/', (String a) => a);
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/'))..close();
|
||||
|
@ -96,7 +96,7 @@ main() {
|
|||
});
|
||||
|
||||
test('global injected serializer', () async {
|
||||
var app = new Angel(MirrorsReflector())..serializer = (_) => 'x';
|
||||
var app = new Angel(reflector: MirrorsReflector())..serializer = (_) => 'x';
|
||||
var http = new AngelHttp(app);
|
||||
app.get($foo.path, (req, ResponseContext res) => res.serialize(null));
|
||||
var rq = new MockHttpRequest('GET', $foo)..close();
|
||||
|
@ -106,7 +106,7 @@ main() {
|
|||
});
|
||||
|
||||
group('handler results', () {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp(app);
|
||||
app.responseFinalizers
|
||||
.add((req, res) => throw new AngelHttpException.forbidden());
|
||||
|
@ -152,7 +152,7 @@ main() {
|
|||
AngelHttp http;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
app.get('/wtf', () => throw new AngelHttpException.forbidden());
|
||||
app.get('/wtf2', () => throw new AngelHttpException.forbidden());
|
||||
http = new AngelHttp(app);
|
||||
|
|
|
@ -20,7 +20,7 @@ main() {
|
|||
http.Client client;
|
||||
|
||||
setUp(() async {
|
||||
app = new Angel(MirrorsReflector())
|
||||
app = new Angel(reflector: MirrorsReflector())
|
||||
..use('/todos', new MapService())
|
||||
..errorHandler = (e, req, res) {
|
||||
print('Whoops: ${e.error}');
|
||||
|
|
|
@ -14,7 +14,7 @@ main() {
|
|||
AngelHttp http;
|
||||
|
||||
setUp(() {
|
||||
app = new Angel(MirrorsReflector());
|
||||
app = new Angel(reflector: MirrorsReflector());
|
||||
http = new AngelHttp(app);
|
||||
|
||||
app.logger = new Logger('streaming_test')
|
||||
|
|
|
@ -4,7 +4,7 @@ import 'package:test/test.dart';
|
|||
|
||||
main() {
|
||||
test('default view generator', () async {
|
||||
var app = new Angel(MirrorsReflector());
|
||||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var view = await app.viewGenerator('foo', {'bar': 'baz'});
|
||||
expect(view, contains('No view engine'));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue