Questions tagged [inversifyjs]

InversifyJS is a lightweight IoC container written in TypeScript.

InversifyJS is a lightweight pico inversion of control (IoC) container for TypeScript and JavaScript apps. A pico IoC container uses a class constructor to identify and inject its dependencies.

InversifyJS is easy to integrate with the majority of existing JavaScript frameworks and encourage the usage of the best OOP and IoC practices.

You can learn more about InversifyJS at http://inversify.io/

197 questions
0
votes
1 answer

Error with responses on nodejs using inversifyjs

I'm using nodejs with typescript, typeorm and inversify to manage dependency injection and inversify express utils to handle controllers, when I send a response inside then or catch block only returns a 204 no content response, but if I send the…
0
votes
1 answer

IOC containers in NPM packages

In our company we have internal SDKs, and sometimes it might be convenient to use inversify within those SDKs. However, I found that it becomes hard to manage all those IOC containers between different packages. For instance if package A depends on…
James
  • 523
  • 4
  • 19
0
votes
1 answer

Adding inversify to existing project breaking the build

So I have an existing typescript/node project which runs and builds fine but when I tried to add inversify to the project using this guide https://medium.com/tkssharma/dependency-injection-setting-up-inversifyjs-ioc-for-typescript-apps-da65edfb1ea8…
0
votes
1 answer

Typescript Inversify: How to bind interface with type parameters

I want to bind an interface that has a type parameter but I am don't how it's done. Interface ... export interface ITestHelper { doSomething(builder: SelectQueryBuilder, pagination: IPaginationParams):…
Emz
  • 475
  • 1
  • 7
  • 16
0
votes
1 answer

How does cross referencing of classes in Javascript/Typescript work?

I'm facing problems in cross referencing of classes even if they are defined in one file. // classes.ts export class A extends BaseModel implements IA { static readonly modelName = 'A'; b?: B; symbol?: string; constructor(object: IA | A =…
Mohsin Amjad
  • 1,045
  • 6
  • 14
0
votes
1 answer

Inversify instance is not injected properly

I'm using inversify in a hapijs v20 and typescript. When I try to bind a dependency in a class that will handle requests like this: import * as Hapi from '@hapi/hapi' import { injectable, inject } from "inversify"; import { types } from…
RicardoE
  • 1,665
  • 6
  • 24
  • 42
0
votes
0 answers

Dependency injection using InversifyJs with an Express controller base and subsclass

My first goal is to avoid repeating myself. I am creating a Node.js express server. I want to create several class controllers each with their own route, and all with the exact same CRUD functionality: GET a single record, GET all the records,…
Gabriel Kunkel
  • 2,643
  • 5
  • 25
  • 47
0
votes
1 answer

How do I tell a Dependency Injection container to share an instance?

I am learning DI with Typescript (I use the tsyringe package in the example). How can I tell a DI container that I want: one new Bar instance for every FooBar Instance (so no singleton) and Foo should reference the Bar instance of FooBar? In the…
Obiwahn
  • 2,677
  • 2
  • 26
  • 36
0
votes
1 answer

Missing @Injectable annotation when importing json value

I'm currently trying to inject a json file into a service that I am building. This class is injecting the json via a @inject() tag in the constructor. Below you can find the code that I'm using. DiContainer.ts import { Container, decorate,…
Jordi
  • 3,041
  • 5
  • 17
  • 36
0
votes
1 answer

How does Inversify's hierarchical DI work?

The inversify-express-utils README contains the following example on request-scoped services. I am trying to implement something similar for a Koa application, however, I struggle to understand how the hierarchical DI in this example works. import {…
Tobi
  • 1,492
  • 1
  • 13
  • 20
0
votes
1 answer

Is it possible to add a decorator to a class after its creation in Typescript?

I would like to update a class with inversify's @injectable decorator after its creation; the use case is I want to use a mocking lib like ts-auto-mock to create a mock for me, and then apply the @injectable decorator after, so I can bind the mock…
halecommarachel
  • 124
  • 1
  • 9
0
votes
1 answer

InfersifyJS - how to conditionally load constantValue

I am using inversifyJS in my typescript + NODE.js application. I have for different environments different configurations: Configuration production const CONFIG_PRODUCTION: Object = { PATH_TO_STATIC_FILES: '../web/build', SECURE_COOKIE:…
MarcoLe
  • 2,309
  • 6
  • 36
  • 74
0
votes
2 answers

InversifyJS uniting testing sinon stub

I'm trying to write unit testing code on my InversifyJS project. Route testing (using supertest) is working properly. Then try to write sinon stub,spy testing, but couldn't be successful. My sample code is given below: DemoRoute @injectable() class…
sabbir
  • 2,020
  • 3
  • 26
  • 48
0
votes
0 answers

How can I bind a service in inversify after another service is initialized?

I use inversify and I have some code that looks like this: export const bindings = new AsyncContainerModule(async (bind) => { await require("./controllers/BaseController"); await…
0
votes
1 answer

DI: constructor of class how injectable calls serveral times

There are several classes, how injected TermsExchangeService: import {TermsExchangeService} from './terms-exchange.service'; @injectable() export class TermsExchangeComponent { constructor( private termsExchangeService:…
user3875721