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/

156 questions
38
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
  • 7,443
  • 8
  • 49
  • 77
12
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,112
  • 4
  • 54
  • 87
10
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 }…
9
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
  • 4,985
  • 3
  • 37
  • 47
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
  • 150,909
  • 47
  • 291
  • 441
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,245
  • 6
  • 36
  • 97
7
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
  • 142
  • 1
  • 6
5
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
  • 41,137
  • 49
  • 170
  • 286
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
  • 3
4
votes
1 answer

Reset scoped container in inversifyjs

I'm implementing a scoped container architecture such that a new container is created for every Express request (or apollographql request). I have a lifecycle method that can be called after we're done sending the response, which is good for…
4
votes
1 answer

InversifyJS @multiInject not working, throws error "Ambiguous match found for serviceIdentifier"

I am using inversifyJs for DI in my typescript project. When using the decorator @multiInject, I am getting the error "Ambiguous match found for serviceIdentifier". I am following this example…
4
votes
1 answer

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 }…
4
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…
Samir
  • 1,288
  • 2
  • 22
  • 41
4
votes
1 answer

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,496
  • 1
  • 20
  • 34
3
votes
2 answers

pass type to dependency injection container

I am supporting multiple databases without using ORM tools. For this example I will show an example for Postgres and MSSQL UserQueries I have an interface IDataBase with multiple databases implementing this interface. @injectable() export class…
1
2 3
10 11