How to use the @loopback/core.extensionFor 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 / extensions / logging / src / logging.component.ts View on Github external
.key]: InvocationLoggingInterceptor,
    };

    if (loggingConfig.enableHttpAccessLog) {
      this.providers[
        LoggingBindings.WINSTON_HTTP_ACCESS_LOGGER.key
      ] = HttpAccessLogInterceptor;
    }

    if (loggingConfig.enableFluent) {
      this.providers[LoggingBindings.FLUENT_SENDER.key] = FluentSenderProvider;
      // Only create fluent transport if it's configured
      this.bindings = [
        Binding.bind(LoggingBindings.WINSTON_TRANSPORT_FLUENT)
          .toProvider(FluentTransportProvider)
          .apply(extensionFor(WINSTON_TRANSPORT)),
      ];
    }
  }
}
github strongloop / loopback-next / extensions / logging / src / __tests__ / accpetance / winston.acceptance.ts View on Github external
it('creates a winston logger with formats', async () => {
    ctx.bind(LoggingBindings.WINSTON_LOGGER).toProvider(WinstonLoggerProvider);
    ctx.configure(LoggingBindings.WINSTON_LOGGER).to({
      level: 'info',
      defaultMeta: {framework: 'LoopBack'},
    });
    const logs: WinstonLogRecord[] = [];
    const myFormat: WinstonFormat = format((info, opts) => {
      logs.push(info);
      return false;
    })();
    ctx
      .bind('logging.winston.formats.myFormat')
      .to(myFormat)
      .apply(extensionFor(WINSTON_FORMAT));
    ctx
      .bind('logging.winston.formats.colorize')
      .to(format.colorize())
      .apply(extensionFor(WINSTON_FORMAT));
    const logger = await ctx.get(LoggingBindings.WINSTON_LOGGER);
    logger.log('info', 'Hello, LoopBack!');
    expect(logs).to.eql([{level: 'info', message: 'Hello, LoopBack!'}]);
  });
github strongloop / loopback-next / extensions / logging / src / __tests__ / accpetance / winston.acceptance.ts View on Github external
it('creates a winston logger with transports', async () => {
    ctx.bind(LoggingBindings.WINSTON_LOGGER).toProvider(WinstonLoggerProvider);
    ctx.configure(LoggingBindings.WINSTON_LOGGER).to({
      level: 'info',
      format: format.json(),
      defaultMeta: {framework: 'LoopBack'},
    });
    const consoleTransport = new WinstonTransports.Console({
      level: 'info',
      format: format.combine(format.colorize(), format.simple()),
    });
    ctx
      .bind('logging.winston.transports.console')
      .to(consoleTransport)
      .apply(extensionFor(WINSTON_TRANSPORT));
    const logger = await ctx.get(LoggingBindings.WINSTON_LOGGER);
    expect(logger.transports).to.eql([consoleTransport]);
  });
github strongloop / loopback-next / examples / greeter-extension / src / types.ts View on Github external
export const asGreeter: BindingTemplate = binding => {
  extensionFor(GREETER_EXTENSION_POINT_NAME)(binding);
  binding.tag({namespace: 'greeters'});
};
github strongloop / loopback-next / packages / model-api-builder / src / model-api-builder.ts View on Github external
export const asModelApiBuilder: BindingTemplate = binding => {
  extensionFor(MODEL_API_BUILDER_PLUGINS)(binding);
  binding.tag({namespace: 'model-api-builders'});
};
github strongloop / loopback4-example-shopping / packages / shopping / src / services / recommender.service.ts View on Github external
const asRecommenderService: BindingTemplate = binding => {
    extensionFor(RECOMMENDER_SERVICE)(binding);
    binding.tag({protocol}).inScope(BindingScope.SINGLETON);
  };
  return asRecommenderService;