Use ThrowingReflector

This commit is contained in:
Tobe O 2019-10-12 09:53:16 -04:00
parent 650cf208fc
commit 6d71707673
2 changed files with 16 additions and 7 deletions

View file

@ -3,6 +3,8 @@
* Add `allowHttp1` to `AngelHttp2` constructors. https://github.com/angel-dart/angel/issues/108 * 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 `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 * 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 # 2.0.4
* Prepare for Dart SDK change to `Stream<List<int>>` that are now * Prepare for Dart SDK change to `Stream<List<int>>` that are now

View file

@ -355,21 +355,28 @@ class Angel extends Routable {
return super.use(path, service)..app = this; 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( Angel(
{Reflector reflector = const EmptyReflector(), {Reflector reflector =
const ThrowingReflector(errorMessage: _reflectionErrorMessage),
this.environment = angelEnv, this.environment = angelEnv,
this.logger, this.logger,
this.allowMethodOverrides = true, this.allowMethodOverrides = true,
this.serializer, this.serializer,
this.viewGenerator}) this.viewGenerator})
: super(reflector) { : super(reflector) {
if (reflector == const EmptyReflector()) { if (reflector is EmptyReflector || reflector is ThrowingReflector) {
var msg = var msg =
'No `reflector` was passed to the Angel constructor, so reflection will not be available.\n' '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, ' _reflectionInfo;
'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); logger?.warning(msg);
} }