diff --git a/CHANGELOG.md b/CHANGELOG.md index 7afe6886..c3f2a4ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.0.0-rc.0 +* Log a warning when no `reflector` is provided. + # 2.0.0-alpha.24 * Add `AngelEnv` class to `core`. * Deprecate `Angel.isProduction`, in favor of `AngelEnv`. diff --git a/example/main.dart b/example/main.dart index 0a07dcd5..9d618393 100644 --- a/example/main.dart +++ b/example/main.dart @@ -4,18 +4,15 @@ import 'package:angel_framework/http.dart'; import 'package:logging/logging.dart'; main() async { - var app = new Angel( + // Logging set up/boilerplate + Logger.root.onRecord.listen(print); + + // Create our server. + var app = Angel( logger: Logger('angel'), reflector: MirrorsReflector(), ); - app.logger = new Logger('angel') - ..onRecord.listen((rec) { - print(rec); - if (rec.error != null) print(rec.error); - if (rec.stackTrace != null) print(rec.stackTrace); - }); - // Index route. Returns JSON. app.get('/', (req, res) => 'Welcome to Angel!'); @@ -44,12 +41,12 @@ main() async { // Simple fallback to throw a 404 on unknown paths. app.fallback((req, res) { - throw new AngelHttpException.notFound( + throw AngelHttpException.notFound( message: 'Unknown path: "${req.uri.path}"', ); }); - var http = new AngelHttp(app); + var http = AngelHttp(app); var server = await http.startServer('127.0.0.1', 3000); var url = 'http://${server.address.address}:${server.port}'; print('Listening at $url'); diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart index 8e944e60..e71e2a09 100644 --- a/lib/src/core/server.dart +++ b/lib/src/core/server.dart @@ -3,8 +3,6 @@ library angel_framework.http.server; import 'dart:async'; import 'dart:collection' show HashMap; import 'dart:convert'; -import 'dart:io'; - import 'package:angel_container/angel_container.dart'; import 'package:angel_http_exception/angel_http_exception.dart'; import 'package:angel_route/angel_route.dart'; @@ -13,7 +11,6 @@ import 'package:http_parser/http_parser.dart'; import 'package:logging/logging.dart'; import 'package:mime/mime.dart'; import 'package:tuple/tuple.dart'; - import 'controller.dart'; import 'env.dart'; import 'hooked_service.dart'; @@ -357,6 +354,16 @@ class Angel extends Routable { this.serializer, this.viewGenerator}) : super(reflector) { + if (reflector == const EmptyReflector()) { + var msg = + 'No `reflector` was passed to the Angel constructor, so reflection will not be available.\n' + 'Features like controllers, constructor dependency injection, and `ioc` require reflection, ' + 'and will not work without it.\n\n' + 'For more, see the documentation:\n' + 'https://docs.angel-dart.dev/guides/dependency-injection#enabling-dart-mirrors-or-other-reflection'; + logger?.warning(msg); + } + bootstrapContainer(); viewGenerator ??= noViewEngineConfigured; serializer ??= json.encode;