Questions tagged [tsyringe]
40 questions
1
vote
1 answer
Registering service with constructor arguments using tsyringe
I have a service to handle some data-fetching and I am trying to use tsyringe with it, the function to create the service gets called multiple times (i cant really do anything about that), so it is creating many instances of the service. I tried to…

Eridanis
- 410
- 1
- 6
- 19
1
vote
2 answers
How to implement singleton in Tsyringe
I am having trouble implementing singleton, because class marked as @singleton() is being recreated on every resolve().
Here is the example
// Foo.ts This is singleton and and must be created only once
import { injectable, singleton } from…

CyberProdigy
- 737
- 9
- 20
1
vote
0 answers
Can't use babel to convert tsyringe typescript files to javascript
It seems that babel/plugin-proposal-decorators is not converting the tsyringe inject() and injectable() to javascript. This is the script that i'm using to convert my typescript files to javascript:
"build": "babel src --extensions \".js,.ts\"…

Mateus Alcantara
- 19
- 2
0
votes
0 answers
Inject TypeORM DataSource using tsyringe in Node.js
I am trying to inject TypeORM data source into repository class using tsyringe DI library, node + express, like this:
const PostgresDataSource = new DataSource({
type: "postgres",
host: process.env.DB_HOST,
port: Number(process.env.DB_PORT),
…

Przemek Wit
- 135
- 3
- 12
0
votes
2 answers
tsyringe - specify which arguments to inject
I am using tsyringe to manage my dependency injection. The following code fragment works.
import 'reflect-metadata'
import {autoInjectable,singleton} from 'tsyringe'
interface sheepProps {
legCount: number
}
@singleton()
export class Animal {
…

SomeDutchGuy
- 2,249
- 4
- 16
- 42
0
votes
0 answers
How to get all decorated classes in Node.js?
I have many decorated classes in different files. Is it possible to get all these classes in one place using a decorator?
In addition, I use the tsyringe library to create decorators. Maybe it has the ability to get classes by decorator?
`export…

Dmitry Belov
- 41
- 3
0
votes
0 answers
What is the best way to get the updated value of the tsyringe.register during the runtime?
I'm wondering is it possible to automatically update the reference to the resolved instance/dependency by the tsyringe container if it had been changed during the runtime?
Basically I'm registering the instance of some class at the…

Velidan
- 5,526
- 10
- 48
- 86
0
votes
0 answers
I am having trouble implementing dependency injection using tsyringe in a React Typescript application with MobX and some inheritance
I have the following test React application:
import "reflect-metadata";
import { observer } from 'mobx-react-lite';
import { observable } from "mobx";
import { container, singleton, injectable } from "tsyringe";
class Person{
@observable…

Ayayron
- 25
- 5
0
votes
0 answers
Class constructor cannot be invoked without new when using tsyringe in react.js app
I am using tsyringe for Dependency Injection in react.js app created using create-react-app. I have a singleton class which is used in other class called TestRepositoryImpl.
import { singleton } from "tsyringe";
@singleton()
class SingletonClass {
…

Akash
- 1
- 2
0
votes
0 answers
Injecting abstract types?
Im trying to wrap my head around TSyringe, having used other IOC's such as Autofac in C# environments, but I must be missing something.
The intend is to register abstract types, to be injected in "greedy constructors" later. I was expecting…

soren.bendtsen
- 405
- 1
- 4
- 9
0
votes
1 answer
How to mock a dependent class without changing constructor parameters to optional in TypeScript & JEST?
I'm trying to imitate something very well-known in mock practice for Java applications, but this time using TypeScript and JEST.
Suppose I have a class Controller who depends on a class Service. The Controller declares its dependency through the…

João Pedro Schmitt
- 1,046
- 1
- 11
- 25
0
votes
1 answer
How to use TypeGraphQL with tsyringe
I have a project using tsyringe and a RESTFul API. Now i should to add a GraphQL API using the type-graphql but in our documentation no have some example using it.
Is possiblem to use tsyringe to make DI with TypeGraphQL?

LeandroLuk
- 154
- 1
- 4
- 11
0
votes
0 answers
"Cannot read properties of undefined reading router" Error message using TSYRINGE
I'm building a class-based restFul API using TypeScript and expressJS with clean architecture, I'm practicing with Typegoose and Tsyringe just to learn how to make dependency injection in this language and framework.
I'm having a problem when trying…

JpCano
- 11
- 2
0
votes
0 answers
How to use tsyringe library Dependency injection while building WebComponents?
I am building an app where we are effectively using https://github.com/microsoft/tsyringe along with Webpack 5. My first few classes and DOM interaction went ahead like a charm including a custom event subscription mechanism.
But now I am stuck…

Gautam
- 1,030
- 13
- 37
0
votes
1 answer
Type Resolution in tsyringe
I recently started using tsyringe and I came across an issue with how dependencies are resolved. A reproducible scenario is explained below:
class Client {
exec(svcNum: number) {
console.log("Executing ", svcNum);
}
}
@injectable()
class…

Abrar Hossain
- 2,594
- 8
- 29
- 54