From 6d71707673512b8fe872e63431d73460c484468a Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 12 Oct 2019 09:53:16 -0400 Subject: [PATCH] Use ThrowingReflector --- CHANGELOG.md | 2 ++ lib/src/core/server.dart | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d596d13..fda36a4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ * Add `allowHttp1` to `AngelHttp2` constructors. https://github.com/angel-dart/angel/issues/108 * Add `deserializeBody` and `decodeBody` to `RequestContext`. https://github.com/angel-dart/angel/issues/109 * Add `HostnameRouter`, which allows for routing based on hostname. https://github.com/angel-dart/angel/issues/110 +* Default to using `ThrowingReflector`, instead of `EmptyReflector`. This will give a more descriptive +error when trying to use controllers, etc. without reflection enabled. # 2.0.4 * Prepare for Dart SDK change to `Stream>` that are now diff --git a/lib/src/core/server.dart b/lib/src/core/server.dart index 5ed7147d..e2f71760 100644 --- a/lib/src/core/server.dart +++ b/lib/src/core/server.dart @@ -355,21 +355,28 @@ class Angel extends Routable { return super.use(path, service)..app = this; } + static const String _reflectionErrorMessage = + ThrowingReflector.defaultErrorMessage + ' ' + _reflectionInfo; + + static const String _reflectionInfo = + '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'; + Angel( - {Reflector reflector = const EmptyReflector(), + {Reflector reflector = + const ThrowingReflector(errorMessage: _reflectionErrorMessage), this.environment = angelEnv, this.logger, this.allowMethodOverrides = true, this.serializer, this.viewGenerator}) : super(reflector) { - if (reflector == const EmptyReflector()) { + if (reflector is EmptyReflector || reflector is ThrowingReflector) { 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'; + 'No `reflector` was passed to the Angel constructor, so reflection will not be available.\n' + + _reflectionInfo; logger?.warning(msg); }