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
56
votes
2 answers

Inversify.js - Reflect.hasOwnMetadata is not a function

I'm trying out Inversify.js for a Typescript application I'm using. Right now, there is no framework involved, so it's pure ES2015. I'm trying to follow along the example in the main page, but I'm being hit with: "Reflect.hasOwnMetadata is not a…
Jose A
  • 10,053
  • 11
  • 75
  • 108
15
votes
1 answer

In Inversify, why to prefer Constructor/Factory injection over toDynamicValue?

In InversifyJS, are there any specific advantages of following the approaches outlined in factory injection guide and constructor injection guide for injecting factories and constructors respectively over just using toDynamicValue.
lorefnon
  • 12,875
  • 6
  • 61
  • 93
13
votes
2 answers

How to inject an asynchronous dependency in inversify?

I have TypeScript application and I'm using Inversify for IoC. I have a connection class: 'use strict'; import { injectable } from 'inversify'; import { createConnection, Connection } from "typeorm"; import { Photo, PhotoMetadata, Author, Album }…
11
votes
1 answer

Babel 7 + Inversify 4 + WebPack 4 - Unexpected character '@' on @inject

I have a typescript Vue SPA project where I use Inversify. I used awesome-typescript-loader for compiling my typescript source code; now I want to switch to Babel but when I compile my application webpack raise this error: Module parse failed:…
Max
  • 6,821
  • 3
  • 43
  • 59
8
votes
2 answers

NestJS Inject module service inside in a non module file

I have a function file for view render and i want to use nestjs modules service in here. My render file is like this. export default { parse() { } render() { } } So to use module service in here i tried to inject like this. import { Inject }…
8
votes
1 answer

Inversify toFactory vs toDynamicValue

This related question shows examples from the documentation but doesn't explain practical difference between InversifyJS toFactory and toDynamicValue toDynamicValue accepts factory function while toFactory accepts higher-order factory function. But…
Estus Flask
  • 206,104
  • 70
  • 425
  • 565
8
votes
1 answer

InversifyJS Injecting Literal Constructor Parameters

Is it possible to get the below behaviour with InversifyJS: constructor(IDependency resolvedDependency, string myLiteral) ^ ^ Automatically resolve Defined Literal If so, what's…
Simon Hardy
  • 140
  • 1
  • 6
7
votes
0 answers

AWS Lambda memory issue while using InversifyJS for DI

I am using InversifyJS with AWS Lambda. I use Typescript and have controller, service and repository layers. In all layers I use constructor injection with InversifyJS. And my function is returning some static dummy text. So the issue is - when I…
0bj3ct
  • 1,400
  • 4
  • 22
  • 51
7
votes
2 answers

TypeError: Reflect.hasOwnMetadata is not a function

I am trying to use inversify with typescript and node.js. I am currently using node.js version 6.9.1, typescript version 2.6.2, and ECMAScript 6. When I try to run the node.js application, I keep receiving the following error, "TypeError:…
user1790300
  • 2,143
  • 10
  • 54
  • 123
6
votes
1 answer

Why is my property injection attempt not injecting anything but undefined?

I have an existing typescript project using inversify. I have defined a logger in my TYPES at TYPES.ILoggger and when I access the logger directly from my container it works: import {ILogger} from "./interfaces/ILogger"; import {TYPES} from…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
5
votes
0 answers

Inversify Tagged vs Named bindings with autoBindInjectable

I've been trying to understand the difference between Inversify @tagged and @named bindings. I cannot seem to find any documentation which defines the difference between the two. They seem rather synonymous. Additionally, when using the…
5
votes
0 answers

InversifyJS binding decorators and lazy inject

I use InversifyJS with binding and lazy inject decorators and I'm getting the next error: No matching bindings found for serviceIdentifier: Symbol(ClassB) Here's the code: inversify.config.ts import { Container } from 'inversify'; import…
5
votes
2 answers

Is it possible to modify or mock the Inversify container used by a Typescript class in a Jasmine unit test?

I have a Typescript class that uses InversifyJS and Inversify Inject Decorators to inject a service into a private property. Functionally this is fine but I'm having issues figuring out how to unit test it. I've created a simplified version of my…
Gavin Sutherland
  • 1,666
  • 3
  • 23
  • 36
5
votes
1 answer

Dependency injection: recommended pattern for injecting NPM modules

I'd like to use Inversify to remove hard dependencies on NPM modules and inject them as constructor arguments instead. This seemed like it would be a lot simpler before I gave it a shot. It turns out that most DefinitelyTyped modules don't bother to…
sbking
  • 7,630
  • 24
  • 33
5
votes
2 answers

InversifyJS: Injecting the class which extends non-injectable external module

Need help on implementation related to Inversify. I am creating a class which is extending EventEmitter from node. when I try to use inversify it says EventEmitter is not injectable. Following is the sample code //Interface export interface…
Hem Upreti
  • 51
  • 1
  • 3
1
2 3
13 14