di.dart
di.dart copied to clipboard
TypeLiteral does not work for non-core types (generator.dart)
To reproduce define two types
@Injectable()
class GenericType<T> {
String desc;
GenericType(this.desc);
}
@Injectable()
class NeedsGenerticTypeString {
GenericType<String> myObj;
NeedsGenerticTypeString(this.myObj);
}
And run the following test:
ii("Non-core types and TypeLiteral do not work with each other", () {
var injector = new ModuleInjector([moduleFactory()
..bind(NeedsGenerticTypeString)
..bind(new TypeLiteral<GenericType<String>>().type, toValue: new GenericType("String"))
]);
expect(() => injector.get(NeedsGenerticTypeString)).not.toThrow();
});
It will fail with "No provider found for GenericType!"
This is because this expression (in generator.dart)
if (typeArgs != null && typeArgs.isNotEmpty && typeArgs.any((arg) => arg is! dynamic))
Will never evaluate to true.
@vsavkin is this fixed now ?
It has not been fixed.