How to use the @loopback/core.Context 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('binds current controller to the request context as singleton', async () => {
      const controller1 = await requestCtx.get(CoreBindings.CONTROLLER_CURRENT);
      expect(controller1).instanceOf(MyController);

      const controller2 = await requestCtx.get(CoreBindings.CONTROLLER_CURRENT);
      expect(controller2).to.be.exactly(controller1);

      const childCtx = new Context(requestCtx);
      const controller3 = await childCtx.get(CoreBindings.CONTROLLER_CURRENT);
      expect(controller3).to.be.exactly(controller1);

      await expect(
        appCtx.get(CoreBindings.CONTROLLER_CURRENT),
      ).to.be.rejectedWith(/The key .+ is not bound to any value/);
    });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / handler-route.unit.ts View on Github external
function givenContextsAndHandlerRoute() {
      const spec = anOperationSpec().build();

      const route = new Route('get', '/greet', spec, () => {});

      appCtx = new Context('application');
      requestCtx = new Context(appCtx, 'request');
      route.updateBindings(requestCtx);
    }
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / handler-route.unit.ts View on Github external
function givenContextsAndHandlerRoute() {
      const spec = anOperationSpec().build();

      const route = new Route('get', '/greet', spec, () => {});

      appCtx = new Context('application');
      requestCtx = new Context(appCtx, 'request');
      route.updateBindings(requestCtx);
    }
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / controller-route.unit.ts View on Github external
function givenContextsAndControllerRoute() {
      const spec = anOperationSpec().build();

      const route = new MyRoute(
        'get',
        '/greet',
        spec,
        MyController,
        myControllerFactory,
        'greet',
      );

      appCtx = new Context('application');
      requestCtx = new Context(appCtx, 'request');
      route.updateBindings(requestCtx);
    }
  });
github strongloop / loopback-next / packages / rest / src / __tests__ / unit / router / controller-route.unit.ts View on Github external
function givenContextsAndControllerRoute() {
      const spec = anOperationSpec().build();

      const route = new MyRoute(
        'get',
        '/greet',
        spec,
        MyController,
        myControllerFactory,
        'greet',
      );

      appCtx = new Context('application');
      requestCtx = new Context(appCtx, 'request');
      route.updateBindings(requestCtx);
    }
  });