How to use the @loopback/core.CoreBindings.CONTROLLER_METHOD_NAME function in @loopback/core

To help you get started, we’ve selected a few @loopback/core 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 / packages / rest / src / __tests__ / unit / router / controller-route.unit.ts View on Github external
it('adds bindings to the request context', async () => {
      expect(requestCtx.contains(CoreBindings.CONTROLLER_CURRENT));
      expect(
        requestCtx.getBinding(CoreBindings.CONTROLLER_CURRENT).scope,
      ).to.equal(BindingScope.SINGLETON);
      expect(await requestCtx.get(CoreBindings.CONTROLLER_CLASS)).to.equal(
        MyController,
      );
      expect(
        await requestCtx.get(CoreBindings.CONTROLLER_METHOD_NAME),
      ).to.equal('greet');
      expect(await requestCtx.get(RestBindings.OPERATION_SPEC_CURRENT)).to.eql({
        'x-controller-name': 'MyController',
        'x-operation-name': 'greet',
        tags: ['MyController'],
        responses: {'200': {description: 'An undocumented response body.'}},
      });
    });
github strongloop / loopback-next / packages / authentication / src / __tests__ / unit / providers / auth-metadata.provider.unit.ts View on Github external
it('returns undefined for a method decorated with @authenticate.skip', async () => {
        const context: Context = new Context();
        context.bind(CoreBindings.CONTROLLER_CLASS).to(TestController);
        context.bind(CoreBindings.CONTROLLER_METHOD_NAME).to('hello');
        context
          .bind(CoreBindings.CONTROLLER_METHOD_META)
          .toProvider(AuthMetadataProvider);
        const authMetadata = await context.get(
          CoreBindings.CONTROLLER_METHOD_META,
        );
        expect(authMetadata).to.be.undefined();
      });
github strongloop / loopback-next / packages / authentication / src / __tests__ / unit / providers / auth-metadata.provider.unit.ts View on Github external
it('returns the auth metadata of a controller method', async () => {
        const context: Context = new Context();
        context.bind(CoreBindings.CONTROLLER_CLASS).to(TestController);
        context.bind(CoreBindings.CONTROLLER_METHOD_NAME).to('whoAmI');
        context
          .bind(CoreBindings.CONTROLLER_METHOD_META)
          .toProvider(AuthMetadataProvider);
        const authMetadata = await context.get(
          CoreBindings.CONTROLLER_METHOD_META,
        );
        expect(authMetadata).to.be.eql({
          strategy: 'my-strategy',
          options: {option1: 'value1', option2: 'value2'},
        });
      });
github strongloop / loopback-next / packages / rest / src / router / controller-route.ts View on Github external
* is invoked.
     *
     * Please note the controller class itself can be bound to other scopes,
     * such as SINGLETON or TRANSIENT (default) in the application or server
     * context.
     *
     * - SINGLETON: all requests share the same instance of a given controller
     * - TRANSIENT: each request has its own instance of a given controller
     */
    requestContext
      .bind(CoreBindings.CONTROLLER_CURRENT)
      .toDynamicValue(() => this._controllerFactory(requestContext))
      .inScope(BindingScope.SINGLETON);
    requestContext.bind(CoreBindings.CONTROLLER_CLASS).to(this._controllerCtor);
    requestContext
      .bind(CoreBindings.CONTROLLER_METHOD_NAME)
      .to(this._methodName);
    requestContext.bind(RestBindings.OPERATION_SPEC_CURRENT).to(this.spec);
  }
github strongloop / loopback-next / packages / authentication / src / providers / auth-metadata.provider.ts View on Github external
constructor(
    @inject(CoreBindings.CONTROLLER_CLASS, {optional: true})
    private readonly controllerClass: Constructor<{}>,
    @inject(CoreBindings.CONTROLLER_METHOD_NAME, {optional: true})
    private readonly methodName: string,
    @config({fromBinding: AuthenticationBindings.COMPONENT})
    private readonly options: AuthenticationOptions = {},
  ) {}
github sourcefuse / loopback4-authorization / src / providers / authorization-metadata.provider.ts View on Github external
constructor(
    @inject(CoreBindings.CONTROLLER_CLASS, {optional: true})
    private readonly controllerClass: Constructor<{}>,
    @inject(CoreBindings.CONTROLLER_METHOD_NAME, {optional: true})
    private readonly methodName: string,
  ) {}
github iqbaldjulfri / lb4-jwt-role-based-auth-sample / src / auth.ts View on Github external
constructor(
    @inject(CoreBindings.CONTROLLER_CLASS, {optional: true}) protected _controllerClass: Constructor<{}>,
    @inject(CoreBindings.CONTROLLER_METHOD_NAME, {optional: true}) protected _methodName: string,
  ) {
    super(_controllerClass, _methodName);
  }