Function SkipSelf

  • Experimental

    Begin searching from the parent container to resolve this identifier.

    The constraints supported are listed in ResolutionConstraintFlag.

    Returns ResolutionConstraintFlag

    The resolution constraint bit-flag for SkipSelf.

    Example

    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 = SkipSelf();

    if (constraintBitMask & ResolutionConstraintFlag.Self) {
    console.log('The dependency will be resolved recursively from the parent.');
    }

    Example

    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, SkipSelf()]
    ])
    class MyService {
    constructor (private name: string) {
    // In this example, $name would evaluate to Joanna instead
    // of Mike. This is due to the SkipSelf decorator.
    }
    }

    childContainer.set({ id: NAME, value: 'Mike' });
    Container.set({ id: NAME, value: 'Joanna' });

    childContainer.get(MyService);

    See

    ResolutionConstraintFlag

Generated using TypeDoc