How to use the @loopback/context.inject.getter function in @loopback/context

To help you get started, we’ve selected a few @loopback/context examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback-next / examples / context / src / dependency-injection.ts View on Github external
}
}

/**
 * A class with dependency injection
 */
class GreetingService {
  // Constructor based injection
  constructor(
    // Inject a context view for all greeters
    @inject.view(filterByTag('greeter'))
    private greetersView: ContextView,
  ) {}

  // Property based injection
  @inject.getter(CURRENT_DATE)
  private now: Getter;

  async greet(
    // Parameter injection
    @inject('currentLanguage')
    language: string,

    // Parameter injection
    @inject('currentUser')
    userName: string,
  ) {
    // Get current date
    const date = await this.now();
    // Get current list of greeters
    const greeters = await this.greetersView.values();
    for (const greeter of greeters) {
github strongloop / loopback-next / packages / authentication / src / providers / auth-action.provider.ts View on Github external
constructor(
    // The provider is instantiated for Sequence constructor,
    // at which time we don't have information about the current
    // route yet. This information is needed to determine
    // what auth strategy should be used.
    // To solve this, we are injecting a getter function that will
    // defer resolution of the strategy until authenticate() action
    // is executed.
    @inject.getter(AuthenticationBindings.STRATEGY)
    readonly getStrategy: Getter,
    @inject.setter(SecurityBindings.USER)
    readonly setCurrentUser: Setter,
  ) {}
github strongloop / loopback4-example-shopping / packages / shopping / src / providers / custom.authentication.provider.ts View on Github external
constructor(
    // The provider is instantiated for Sequence constructor,
    // at which time we don't have information about the current
    // route yet. This information is needed to determine
    // what auth strategy should be used.
    // To solve this, we are injecting a getter function that will
    // defer resolution of the strategy until authenticate() action
    // is executed.
    @inject.getter(AuthenticationBindings.STRATEGY)
    readonly getStrategy: Getter,
    @inject.setter(AuthenticationBindings.CURRENT_USER)
    readonly setCurrentUser: Setter,
  ) {}
github gobackhuoxing / first-web-game-lb4 / firstgame / src / interceptors / authorize.interceptor.ts View on Github external
constructor(
    @inject(AuthenticationBindings.METADATA)
    public metadata: AuthenticationMetadata,
    @inject(MyAuthBindings.USER_PERMISSIONS)
    protected checkPermissons: UserPermissionsFn,
    @inject.getter(AuthenticationBindings.CURRENT_USER)
    public getCurrentUser: Getter,
  ) {}
github sourcefuse / loopback4-authorization / src / providers / authorization-action.provider.ts View on Github external
constructor(
    @inject.getter(AuthorizationBindings.METADATA)
    private readonly getMetadata: Getter,
    @inject(AuthorizationBindings.PATHS_TO_ALLOW_ALWAYS)
    private readonly allowAlwaysPath: string[],
  ) {}
github strongloop / loopback-next / packages / repository / src / decorators / repository.decorator.ts View on Github external
export function getter(nameOrClass: string | Class>) {
    const name =
      typeof nameOrClass === 'string' ? nameOrClass : nameOrClass.name;
    return inject.getter(`repositories.${name}`);
  }
}