How to use the @loopback/core.inject 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 / v3compat / src / remoting / lb3-model-controller.ts View on Github external
// Node module: @loopback/v3compat
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {inject} from '@loopback/core';
import {OperationArgs, Request, Response, RestBindings} from '@loopback/rest';
import * as debugFactory from 'debug';
import {SharedMethod} from './shared-method';

const debug = debugFactory('loopback:v3compat:rest-adapter');

export class Lb3ModelController {
  @inject(RestBindings.Http.REQUEST)
  protected request: Request;

  @inject(RestBindings.Http.RESPONSE)
  protected response: Response;

  // TODO: a property for strong-remoting's HttpContext

  [key: string]: Function | Request | Response;

  protected buildMethodArguments(
    sharedMethod: SharedMethod,
    inputArgs: OperationArgs,
  ) {
    const finalArgs: OperationArgs = [];
    for (const argSpec of sharedMethod.accepts) {
      const source = argSpec.http && argSpec.http.source;
      switch (source) {
        case 'req':
          finalArgs.push(this.request);
github strongloop / loopback4-example-shopping / packages / shopping / src / services / hash.password.bcryptjs.ts View on Github external
constructor(
    @inject(PasswordHasherBindings.ROUNDS)
    private readonly rounds: number,
  ) {}
github sourcefuse / loopback4-authorization / src / component.ts View on Github external
constructor(
    @inject(AuthorizationBindings.CONFIG)
    private readonly config?: AuthorizationConfig,
  ) {
    this.providers = {
      [AuthorizationBindings.AUTHORIZE_ACTION.key]: AuthorizeActionProvider,
      [AuthorizationBindings.METADATA.key]: AuthorizationMetadataProvider,
      [AuthorizationBindings.USER_PERMISSIONS.key]: UserPermissionsProvider,
    };

    if (
      config &&
      config.allowAlwaysPaths &&
      config.allowAlwaysPaths.length > 0
    ) {
      this.bindings = [
        Binding.bind(AuthorizationBindings.PATHS_TO_ALLOW_ALWAYS).to(
          config.allowAlwaysPaths,
github strongloop / loopback-next / packages / booter-lb3app / src / lb3app.booter.ts View on Github external
constructor(
    @inject(CoreBindings.APPLICATION_INSTANCE)
    public app: RestApplication,
    @inject(BootBindings.PROJECT_ROOT)
    public projectRoot: string,
    @inject(`${BootBindings.BOOT_OPTIONS}#lb3app`)
    options: Partial = {},
  ) {
    this.options = Object.assign({}, DefaultOptions, options);

    if (typeof app.mountExpressRouter !== 'function') {
      throw new Error(
        'Lb3AppBooter requires RestApplication with mountExpressRouter API',
      );
    }
  }
github strongloop / loopback4-example-shopping / packages / shopping / src / authentication-strategies / JWT.strategy.ts View on Github external
constructor(
    @inject(JWTAuthenticationBindings.SERVICE)
    public jwt_authentication_service: JWTAuthenticationService,
    @inject(JWTAuthenticationBindings.SECRET)
    public jwt_secret: string,
  ) {}
  async authenticate(request: Request): Promise {
github strongloop / loopback4-example-shopping / packages / shopping / src / repositories / order.repository.ts View on Github external
constructor(
    @inject('datasources.mongo') protected datasource: juggler.DataSource,
  ) {
    super(Order, datasource);
  }
}
github strongloop / loopback-next / packages / rest-crud / src / crud-rest-builder.plugin.ts View on Github external
function setupCrudRepository(
  entityClass: typeof Entity & {prototype: Entity},
  modelConfig: ModelCrudRestApiConfig,
): Class> {
  const repositoryClass = defineRepositoryClass(entityClass);

  inject(`datasources.${modelConfig.dataSource}`)(
    repositoryClass,
    undefined,
    0,
  );

  return repositoryClass;
}
github strongloop / loopback4-example-shopping / packages / shopping / src / repositories / user.repository.ts View on Github external
constructor(
    @inject('datasources.mongo') protected datasource: juggler.DataSource,
    @repository(OrderRepository) protected orderRepository: OrderRepository,
    @repository.getter('UserCredentialsRepository')
    protected userCredentialsRepositoryGetter: Getter<
      UserCredentialsRepository
    >,
  ) {
    super(User, datasource);
    this.userCredentials = this.createHasOneRepositoryFactoryFor(
      'userCredentials',
      userCredentialsRepositoryGetter,
    );
    this.orders = this.createHasManyRepositoryFactoryFor(
      'orders',
      async () => orderRepository,
    );
  }