How to use the @loopback/context.BindingScope.TRANSIENT 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 / packages / core / src / __tests__ / unit / application.unit.ts View on Github external
it('binds a server with a different scope than SINGLETON', async () => {
      @bind({scope: BindingScope.TRANSIENT})
      class TransientServer extends FakeServer {}

      const binding = app.server(TransientServer);
      expect(binding.scope).to.equal(BindingScope.TRANSIENT);
    });
github strongloop / loopback-next / packages / core / src / __tests__ / unit / application.unit.ts View on Github external
it('binds a controller', () => {
      const binding = app.controller(MyController);
      expect(Array.from(binding.tagNames)).to.containEql(CoreTags.CONTROLLER);
      expect(binding.key).to.equal('controllers.MyController');
      expect(binding.scope).to.equal(BindingScope.TRANSIENT);
      expect(findKeysByTag(app, CoreTags.CONTROLLER)).to.containEql(
        binding.key,
      );
    });
github strongloop / loopback-next / packages / core / src / __tests__ / unit / application.unit.ts View on Github external
it('binds a transient component', () => {
      @bind({scope: BindingScope.TRANSIENT})
      class MyTransientComponent {}

      const binding = app.component(MyTransientComponent);
      expect(binding.scope).to.equal(BindingScope.TRANSIENT);
    });
github strongloop / loopback-next / packages / core / src / __tests__ / unit / application.unit.ts View on Github external
it('binds a server with a different scope than SINGLETON', async () => {
      @bind({scope: BindingScope.TRANSIENT})
      class TransientServer extends FakeServer {}

      const binding = app.server(TransientServer);
      expect(binding.scope).to.equal(BindingScope.TRANSIENT);
    });
github strongloop / loopback-next / packages / repository / src / mixins / repository.mixin.ts View on Github external
repository>(
      repoClass: Class,
      name?: string,
    ): Binding {
      const binding = createBindingFromClass(repoClass, {
        name,
        namespace: 'repositories',
        type: 'repository',
        defaultScope: BindingScope.TRANSIENT,
      });
      this.add(binding);
      return binding;
    }
github strongloop / loopback-next / packages / boot / src / booters / interceptor.booter.ts View on Github external
async load() {
    await super.load();

    this.interceptors = this.classes as InterceptorProviderClass[];
    for (const interceptor of this.interceptors) {
      debug('Bind interceptor: %s', interceptor.name);
      const binding = createBindingFromClass(interceptor, {
        defaultScope: BindingScope.TRANSIENT,
      });
      this.app.add(binding);
      debug('Binding created for interceptor: %j', binding);
    }
  }
}
github strongloop / loopback-next / packages / repository / src / mixins / repository.mixin.ts View on Github external
repository>(
      repoClass: Class,
      name?: string,
    ): Binding {
      const binding = createBindingFromClass(repoClass, {
        name,
        namespace: 'repositories',
        type: 'repository',
        defaultScope: BindingScope.TRANSIENT,
      });
      this.add(binding);
      return binding;
    }
github strongloop / loopback-next / packages / authentication / src / providers / auth-strategy.provider.ts View on Github external
AuthenticationStrategy,
  AUTHENTICATION_STRATEGY_NOT_FOUND,
} from '../types';

/**
 * An authentication strategy provider responsible for
 * resolving an authentication strategy by name.
 *
 * It declares an extension point to which all authentication strategy
 * implementations must register themselves as extensions.
 *
 * @example `context.bind('authentication.strategy').toProvider(AuthenticationStrategyProvider)`
 */
@extensionPoint(
  AuthenticationBindings.AUTHENTICATION_STRATEGY_EXTENSION_POINT_NAME,
  {scope: BindingScope.TRANSIENT},
) //this needs to be transient, e.g. for request level context.
export class AuthenticationStrategyProvider
  implements Provider {
  constructor(
    @extensions()
    protected authenticationStrategies: Getter,
    @inject(AuthenticationBindings.METADATA)
    protected metadata?: AuthenticationMetadata,
  ) {}
  async value(): Promise {
    if (!this.metadata) {
      return undefined;
    }
    const name = this.metadata.strategy;
    const strategy = await this.findAuthenticationStrategy(name);
    if (!strategy) {