fix(di): allow dependencies as flat array

This commit is contained in:
mgechev 2015-10-27 17:45:24 -07:00 committed by vsavkin
parent c02f2bdab0
commit 6514b8ced0
2 changed files with 16 additions and 1 deletions

View File

@ -642,7 +642,13 @@ function _extractToken(typeOrFunc, metadata /*any[] | any*/, params: any[][]): D
var optional = false;
if (!isArray(metadata)) {
return _createDependency(metadata, optional, null, null, depProps);
if (metadata instanceof InjectMetadata) {
var metaArrayWrapper = ListWrapper.createFixedSize(1);
metaArrayWrapper[0] = metadata;
metadata = metaArrayWrapper;
} else {
return _createDependency(metadata, optional, null, null, depProps);
}
}
var lowerBoundVisibility = null;

View File

@ -648,6 +648,15 @@ export function main() {
});
});
it('should allow declaring dependencies with flat arrays', () => {
var resolved =
Injector.resolve([bind('token').toFactory(e => e, [new InjectMetadata("dep")])]);
var nestedResolved =
Injector.resolve([bind('token').toFactory(e => e, [[new InjectMetadata("dep")]])]);
expect(resolved[0].resolvedFactories[0].dependencies[0].key.token)
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
});
describe("displayName", () => {
it("should work", () => {
expect(Injector.resolveAndCreate([Engine, BrokenEngine]).displayName)