Experimental
The resolution constraint bit-flag for Self.
This function can be used to construct a bitmask for use in the dependencies array of a service. While this can be used publicly, it is mainly for use within TypeDI; it allows you to configure specific constraints for use when resolving a specific service.
const constraintBitMask = Self();
if (constraintBitMask & ResolutionConstraintFlag.Self) {
console.log('The dependency will not be resolved recursively.');
}
Here is an example of this constraint as part of a service declaration:
const NAME = new Token<string>('name');
const childContainer = Container.ofChild(Symbol());
@Service({ container: childContainer }, [
[NAME, Self()]
])
class MyService {
constructor (private name: string) { }
}
Container.set({ id: NAME, value: 'Joanna' });
childContainer.get(MyService);
// -> throws ServiceNotFoundError(Token<name>)
It is advised to combine this with Optional, as the usage of this constraint may mean that the identifier cannot be resolved.
Generated using TypeDoc
Do not ascend the container tree to resolve this identifier.
The constraints supported are listed in ResolutionConstraintFlag.