fix(di): allow dependencies as flat array
This commit is contained in:
parent
c02f2bdab0
commit
6514b8ced0
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue