1.0.4
This commit is contained in:
parent
3e434fc6dc
commit
c5827c09f2
4 changed files with 42 additions and 7 deletions
|
@ -1,3 +1,6 @@
|
|||
# 1.0.4
|
||||
* Slight patch to prevent annoying segfault.
|
||||
|
||||
# 1.0.3
|
||||
* Added `Future` support to `Reflector`.
|
||||
|
||||
|
|
|
@ -59,14 +59,27 @@ class Container {
|
|||
///
|
||||
/// It is similar to [make], but resolves an injection of either
|
||||
/// `Future<T>` or `T`.
|
||||
Future<T> makeAsync<T>() async {
|
||||
if (has<Future<T>>()) {
|
||||
Future<T> makeAsync<T>([Type type]) {
|
||||
type ??= T;
|
||||
Type futureType = null; //.Future<T>.value(null).runtimeType;
|
||||
|
||||
if (T == dynamic) {
|
||||
try {
|
||||
futureType = reflector.reflectFutureOf(type).reflectedType;
|
||||
} on UnsupportedError {
|
||||
// Ignore this.
|
||||
}
|
||||
}
|
||||
|
||||
if (has<T>(type)) {
|
||||
return Future<T>.value(make(type));
|
||||
} else if (has<Future<T>>()) {
|
||||
return make<Future<T>>();
|
||||
} else if (has<T>()) {
|
||||
return Future<T>.value(make<T>());
|
||||
} else if (futureType != null) {
|
||||
return make(futureType);
|
||||
} else {
|
||||
throw new ReflectionException(
|
||||
'No injection for Future<$T> or $T was found.');
|
||||
'No injection for Future<$type> or $type was found.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ class MirrorsReflector extends Reflector {
|
|||
}
|
||||
|
||||
var future = dart.reflectType(Future, [_mirror.reflectedType]);
|
||||
return _ReflectedTypeMirror(future);
|
||||
return _ReflectedClassMirror(future as dart.ClassMirror);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1,7 +1,26 @@
|
|||
import 'dart:async';
|
||||
import 'package:angel_container/angel_container.dart';
|
||||
import 'package:angel_container/mirrors.dart';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'common.dart';
|
||||
|
||||
void main() {
|
||||
testReflector(const MirrorsReflector());
|
||||
|
||||
test('futureOf', () {
|
||||
var r = MirrorsReflector();
|
||||
var fStr = r.reflectFutureOf(String);
|
||||
expect(fStr.reflectedType.toString(), 'Future<String>');
|
||||
// expect(fStr.reflectedType, Future<String>.value(null).runtimeType);
|
||||
});
|
||||
|
||||
test('concrete future make', () async {
|
||||
var c = Container(MirrorsReflector());
|
||||
c.registerFactory<Future<String>>((_) async => 'hey');
|
||||
var fStr = c.reflector.reflectFutureOf(String);
|
||||
var s1 = await c.make(fStr.reflectedType);
|
||||
var s2 = await c.makeAsync(String);
|
||||
print([s1, s2]);
|
||||
expect(s1, s2);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue