tsyringe#container TypeScript Examples

The following examples show how to use tsyringe#container. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppointmentsController.ts    From gobarber-api with MIT License 6 votes vote down vote up
public async craete(req: Request, res: Response): Promise<Response> {
    const user_id = req.user.id;
    const { provider_id, date } = req.body;

    const createAppointment = container.resolve(CreateAppointmentService);

    const appointment = await createAppointment.execute({
      provider_id,
      date,
      user_id,
    });

    return res.json(appointment);
  }
Example #2
Source File: CustomersController.ts    From rocketseat-gostack-11-desafios with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const { name, email } = request.body;

    const createCustomer = container.resolve(CreateCustomerService);

    const customer = await createCustomer.execute({ name, email });

    return response.json(customer);
  }
Example #3
Source File: BullQueueProvider.ts    From hotseat-api with MIT License 6 votes vote down vote up
public init(): void {
    const queues = Object.values(jobs).map(job => {
      const jobInstance = container.resolve(job);

      return {
        key: jobInstance.key,
        queue: new Queue(jobInstance.key, { redis: redisConfig }),
        handle: jobInstance.handle,
      };
    });

    this.queues = queues;
  }
Example #4
Source File: ItemsController.ts    From ecoleta with MIT License 6 votes vote down vote up
public async index(request: Request, response: Response): Promise<Response> {
    const listItems = container.resolve(ListItemsService);

    const items = await listItems.execute();

    const serializedItems = items
      ? items.map(({ id, title, image }) => ({
          id,
          title,
          image_url: `http://192.168.0.185:3333/uploads/${image}`,
        }))
      : items;

    return response.json(serializedItems);
  }
Example #5
Source File: vscode-control.ts    From vs-code-conan with MIT License 6 votes vote down vote up
constructor(context: vscode.ExtensionContext, 
        state: AppState,
        @inject("Executor") executor?:Executor) {
        if(!executor){
            throw Error("executor has to be defined");
        }
        this.executor = executor;
        this.commands=container.resolve(Commands);
        this._state = CommandController.updateState(state);
        this.context = context;
        state.activeProfile = ALL;
    }
Example #6
Source File: install.ts    From hexon with GNU General Public License v3.0 6 votes vote down vote up
export default async function () {
  console.clear()
  console.log(chalk.blue(logo))

  printVersion()

  printer.section("Configuration")
  const storage = container.resolve(StorageService)
  storage.set<string>(HEXON_PORT_KEY, await getPort())
  storage.set<string>(HexoInstanceService.HEXO_BASE_DIR_KEY, await getRoot())
  const { username, password } = await getUserInfo()
  const account = container.resolve(AccountService)
  account.setUserInfo(username, password)

  printer.section("Install")
  const base = path.resolve(__dirname, "../..")
  printer.success(`Hexon has been installed to \`${base}\``)
  printer.log(`Run \`pnpm start\` to start`)
  printer.log(`Run \`pnpm prd\` to start with pm2`)
  printer.log(chalk.grey(`To uninstall, remove the following foler: ${base}`))
}
Example #7
Source File: DataModule.ts    From rn-clean-architecture-template with MIT License 6 votes vote down vote up
export function registerDataDependencies() {
  container.register(AppDependencies.ApiProvider, {
    useValue: new BearerAuthorizationRxAxiosProvider({
      baseURL: BuildConfig.ApiUrl,
    }),
  });
  container.register(AppDependencies.LocalAuthenticationDataSource, {
    useClass: KeyChainAuthenticationDataSource,
  });

  container.register(AppDependencies.RemoteAuthenticationDataSource, {
    useClass: ApiAuthenticationDataSource,
  });

  container.register(AppDependencies.SignInUseCase, {
    useClass: SignInUseCase,
  });
}
Example #8
Source File: AppointmentsController.ts    From gobarber-project with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const user_id = request.user.id;
    const { provider_id, date } = request.body;

    const createAppointment = container.resolve(CreateAppointmentService);

    const appointment = await createAppointment.execute({
      provider_id,
      user_id,
      date,
    });

    return response.json(appointment);
  }
Example #9
Source File: AppointmentsController.ts    From GoBarber with MIT License 6 votes vote down vote up
public async create(request: Request, response: Response): Promise<Response> {
    const { provider_id, date } = request.body;
    const { id: user_id } = request.user;

    const createAppointment = container.resolve(CreateAppointmentService);

    const appointment = await createAppointment.execute({
      provider_id,
      user_id,
      date,
    });

    return response.status(200).json(appointment);
  }
Example #10
Source File: tarkov.ts    From tarkov with MIT License 6 votes vote down vote up
/**
   * Move an item
   * UNTESTED
   * @async
   * @param {string} itemId collect item id
   * @param {ItemDestination} destination - info where to move. {id, container, location:{x,y,r} }
   * @param {String} destination.id - item id where we move
   * @param {String} [destination.container="hideout"] - 'main' = container, 'hideout' = stash
   * @param {Object} [destination.location={x:0,y:0,r:0}] - {x, y, r} x & y locations, topleft is 0,0. r = 0 or 1.
   */
  public async moveItem(itemId: string, destination: ItemDestination): Promise<any> {
    const body = JSON.stringify({
      data: [{
        Action: 'Move',
        item: itemId,
        to: {
          container: 'hideout', // main = container, hideout = stash 
          location: { x: 0, y: 0, r: 0 }, // try to put to topleft if empty
          ...destination,
        },
      }],
      tm: 2,
    });
    const result: ApiResponse<any> = await this.api.prod.post('client/game/profile/items/moving', { body });
    return result.body.data;
  }
Example #11
Source File: ProvidersController.ts    From gobarber-api with MIT License 5 votes vote down vote up
public async index(req: Request, res: Response): Promise<Response> {
    const user_id = req.user.id;

    const listProviders = container.resolve(ListProvidersService);

    const providers = await listProviders.execute({ user_id });

    return res.json(classToClass(plainToClass(User, providers)));
  }
Example #12
Source File: index.ts    From rocketseat-gostack-11-desafios with MIT License 5 votes vote down vote up
container.registerSingleton<ICustomersRepository>(
  'CustomersRepository',
  CustomersRepository,
);
Example #13
Source File: index.ts    From hotseat-api with MIT License 5 votes vote down vote up
container.registerSingleton<IHashProvider>('HashProvider', BCryptHashProvider);
Example #14
Source File: AdrGwContainer.ts    From ADR-Gateway with MIT License 5 votes vote down vote up
AdrGwContainer = container.createChildContainer()