Open xenoterracide opened 4 years ago
Can you write a simple unit test that can repro this?
tried writing this unit test as a PR, but for some reason this doesn't compile in project... this reproduces, the child container is necessary.
import { container, injectable, registry } from 'tsyringe';
test('isRegistered', () => {
interface MyType {
}
@injectable()
class Foo implements MyType {
}
@injectable()
class Bar implements MyType {
}
@registry([
{ token: 'MyType', useToken: Foo },
{ token: 'MyType', useToken: Bar },
])
class Config {
}
const child = container.createChildContainer();
expect(child.resolveAll<MyType>('MyType')).toHaveLength(2);
expect(child.isRegistered('MyType')).toBe(true);
});
it is possible, even probable that this is the expected behavior on a child, but from what I can tell this leaves us without a good way to check if a collection is resolvable at all.
You should pass true
as the second parameter for the isRegistered
method to allow a recursive search on parent containers.
child.isRegistered('MyType', true)
title might be wrong, here's what I'm doing
now this code elsewhere does not work, I get the empty array
this however does work, and I get the one resolver, and the removal of the ternary is the only thing I've changed.
note:
resolver()
just returns my deepest child container...Version: 4.0.1