Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Narcis B.
    We also have a discord server, if you are interested! click here
    Luiz Guilherme D'Abruzzo Pereira
    Hello everyone :wave: I've opened a inversify/InversifyJS#1345 to add a functionally that was inversify/InversifyJS#1110 by multiple people. I was wondering if one of the maintainers could have a look at my pr. Also, I'm open to be one of the maintainers of the project reviewing PRs, answering questions in issues and working on new functionality. The project I'm currently working relies heavily on inversify and we really don't want this project to die.
    Francesco Ferraioli


    Just wondering when the onDeactivation handler is planned to be release? Also, will the handler be invoked when the container is stopped?

    David Hart
    I'm trying to depend on InversifyJS master from my project as I need some of the new features not available in 5.1.1. Is there an easy way to do it?
    Hi all,
    Just wondering , is there way we can auto inject interface?
    'autoBindInjectable' should only work with concrete type, right?
    After all , how could we hold the reference to the interface implementation?
    Lemon King
    Good evening everyone, how do I make a generic provider/factory? Making the handler a generic would require setting the generic in the module which is not what I need. Here's what I'm trying to do https://dpaste.com/DTUHD4DGF
    Michael Harrington

    Why is @injectable() necessary?

    Is it possible to make a library inversify-compatible without either 1. having a dependency on inversify so you can @injectable() the classes in the lib itself or 2. putting the burden on the application to decorate() everything after the fact?

    Josh Crompton
    Hi; is it possible to inject multiple implementations of the same interface into a constructor using named bindings? I'm running into an error when I try and do it and I'm not sure if it's a limitation of the library or if I'm holding it wrong.
    I have two implementations with separate named bindings:
    In my tests I rebind them like so:
    Josh Crompton
    And they're being injected into the constructor of the class under test like so:
    export class AuthorizationService {
            @inject(TYPE_ID.Authorizer) @named('LOCATION') private readonly locationAuthorizer: IAuthorizer,
            @inject(TYPE_ID.Authorizer) @named('TOKEN') private readonly tokenAuthorizer: IAuthorizer,
        ) {}
    And the tests fail to run with the following error:
        No matching bindings found for serviceIdentifier: Symbol(Authoriser)
         Symbol(Authoriser) - named: LOCATION
          46 |         container.rebind(TYPE_ID.Authorizer).toConstantValue(mockTokenActionAuthorizer).whenTargetNamed('TOKEN');
          47 |
        > 48 |         authService = container.get(AuthorizationService);
             |                                 ^
          49 |     });
          50 |
          51 |     beforeEach(() => {
    Should I be using @multiInject instead? Can I even rebind named bindings?
    Josh Crompton

    It started working if I change the rebinding in the tests to:


    I don't understand why that works at all (surely you have to bind before you can rebind?) but maybe this info will be useful for someone else...

    Narcis B.
    @jscn Hey, the problem seems to be solved in the unreleased version (master branch).
    Jake Hamilton
    Hello! Where can I find information about the release schedule (if any exists) for inversifyjs?
    Simon Renoult
    This message was deleted
    Slim Hmidi
    I have a question about a design related to the inversify DI;
    Can I add a customer decorator @Config for example which allows the injector to locate the config file of the class and initialize the attributes in its constructor or its an anti-pattern and the injector should be only responsible for instantiation and config should be done in the class declaration?
    Hi! Have anyone encountered error “ambiguous identifier match for X” when using hot reload and dynamic module import?
    Hi there, I get this error when I build my project with webpack
    Uncaught Exception:
    Error: Two controllers cannot have the same name: e
    I think this problem is webpack. When I build it changes the function name.
    like this
    function e(e){this.sqliteClient=e}
    orginal naming : function GameService(GameService){this.sqliteClient=SqliteClient}
    how can i solve this problem
    Atanas Kaynarov
    Hello. I have a question regarding circular dependencies. I have dependency tree A -> B -> A. And currently inversify is throwing an exception for it. Both serviceses are SingletonScoped . How can I achieve this?
    Dan Visel

    Hi! I'm trying to use an Inversify-based library in non-Typescript codebase. How would I go about changing code that looks like this:

      constructor(@inject('Display') display, @inject('Text') text) {

    to a more ES5-friendly version? I have enough Babel plugins running that the above works correctly, though it makes my eslint deeply unhappy.

    Hi all, Need some help! I'm writing unit test to check if container resolves required set of services in the factory, depending on config I'm passing in. But I'm receiving an errors either 'there is no bind for the Symbol' or 'no binding found for the Array'. If somebody knows how to fixed, please help!
    Nima Adibpour
    Hey there
    I have this question I'm having trouble finding a clear answer to online so figured I'd post here. My class structure is basically such that I have an abstract class which needs certain dependencies to get injected into it for the basic functionality that it provides to all its sub-classes. My goal is to avoid having every sub-class have to define @inject several times in their ctor and instead find a way to just do it on the base class once. Is this possible?
    Hello everyone, i have this question:
    Using inversify, im creating a ContainerModule with class Library1 , then over inversify.config.ts file, i have load that module, and in my class Test i have injected that Library1 using @inject(Types.Library1) private library: Library1). Now, im trying to use jest to do proper testings, but i want to rebind that Library1 and replaced with a mock and then injected to Test class. Is this possible ?
    Hello everyone, it is possible to tag on fly when bind(type).toDybamicValue(() => {}).when((request)) ?
    Gustavo Lanna
    Hello everyone, is it possible to use the request scope with fluentProvide?
    Narcis B.
    Please upgrade the extension and try again.
    Gustavo Lanna
    Thanks for replying. I'm using the version 4.0.0, and I cannot find any option to work with request scope
    Jerry Lin
    I'm trying to use inversify-binding-decorators using classes as service identifiers in a TS application, but I get some frustrating issues with Jest throwing "ReferenceError: Cannot access '<class in decorator>' before initialization" errors.
    Anyone find a solution to this? I can get around it by using string identifiers or plain injectable() which doesn't take a Class as a parameter. I've tried making a decorator alias (e.g., @providesAlias with no param) that applies @provides(<Class>) which gets around the jest issue, but doesn't work for retrieving the instance when I use container.get(<Class>);
    Jerry Lin
    Found a fix from this open issue: inversify/inversify-binding-decorators#185
    Anthony Paquet
    Hey guys, does it exist a library to help doing TDD ? As far as I know I need to rebind all my container in the test. I wonder if there is a way to reuse the src container ? I hope the question is clear enough !
    Anthony Paquet
    I found the solution. I imported my container and then used
    Nicolas De Boose

    Hello folks,

    I have a little question :) I really hope you could help me:

    I have a problem when importing lodash (or any lib/file that exports a default) like this: import _ from 'lodash';. As soon as I use @injectable on my Typescript class, it compiles the code differently and lodash is becoming undefined. I've set esModuleInterop:truebut it seems that as soon as I'm using @injectable, it's like it doesn't care about it anymore

    Nicolas De Boose
    Issue because of typescript => microsoft/TypeScript#27293

    I have some issues with Inversify package(which is a peer-dep) when running webpack serve. The error:

    ERROR in ../node_modules/mana-syringe/src/inversify/index.ts 1:12
    Module parse failed: Unexpected token (1:12)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
    > import type { interfaces } from 'inversify';
    | import { Container } from 'inversify';
    | import { Syringe, Utils } from '../core';
    ℹ 「wdm」: Failed to compile.

    I use webpack and babel loader with the following configs:

      "compilerOptions": {
        "allowJs": true,
        "allowSyntheticDefaultImports": true,
        "declaration": true,
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "forceConsistentCasingInFileNames": true,
        "isolatedModules": true,
        "jsx": "react",
        "lib": ["dom", "dom.iterable", "esnext", "es6"],
        "module": "es6",
        "moduleResolution": "node",
        "noEmit": true,
        "noImplicitAny": false,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "resolveJsonModule": true,
        "target": "es5",
        "skipLibCheck": true,
        "sourceMap": true,
        "strict": true,
        "types": ["reflect-metadata"]
      "include": ["src"],
      "exclude": ["node_modules", "dist", "config"]
    const isDev = environment === 'development';
    const babelOptions = {
      babelrc: false,
      presets: [
          // 'es2017', 'es2016', 'es2015',
            targets: 'last 3 versions'
      plugins: []
    module.exports = {
      cache: true,
      context: paths.appSrc,
      plugins: [
        new ForkTsCheckerWebpackPlugin({
          async: isDev,
          typescript: {
            configFile: paths.appTSJson,
            context: paths.appPath,
            configOverwrite: {
              compilerOptions: {
                sourceMap: isDev,
                inlineSourceMap: false,
                declarationMap: false
              exclude: ['**/*.test.js', '**/*.test.jsx', '**/*.test.ts', '**/*.test.tsx']
        new CopyPlugin({
          patterns: [
              from: 'assets',
              to: 'assets/',
              cacheTransform: true
        new HtmlWebPackPlugin({
          template: paths.appHtml,
          minify: {
            removeComments: true,
            collapseWhitespace: false
        new webpack.DefinePlugin({
          'process.env': JSON.stringify(env)
      resolve: {
        modules: ['node_modules', 'src'],
        extensions: ['.js', '.jsx', '.ts', '.tsx']
      module: {
        rules: [
            test: /\.(js|jsx)?$/,
            include: [paths.appSrc],
            exclude: [paths.appNodeModules],
            use: [
                loader: 'babel-loader',
                options: babelOptions
            test: /\.(ts|tsx)?$/,
            include: [
              // path.resolve(paths.appNodeModules, 'mana-syringe'),
              // path.resolve(paths.appNodeModules, 'inversify')
            exclude: [paths.appNodeModules],
            use: [
                loader: 'babel-loader',
                options: {
                  presets: [
                    ['@babel/preset-typescript', { onlyRemoveTypeImports: true }]
                  plugins: [
                    ['@babel/plugin-proposal-class-properties', { legacy: true }],
                    ['@babel/plugin-proposal-decorators', { legacy: true }]
              // {
              //   loader: 'ts-loader',
              //   options: {
              //     configFile: paths.appTSJson,
              //     allowTsInNodeModules: true,
              //     transpileOnly: true
              //   }
              // }

    Hi guys! I am starting a new project creating a Telegram bot with inversify. I have previously used it on my web servers and it worked creating a child container for the requests to initiate some context for each request. I am wondering how to do that with my custom set up, as I am not sure how @injectable works as it magically injects the class from the main container. Could you point me to the documentation if I can specify a container to inject from?

    An example of one of the classes I am injecting the instances:

    import {injectable} from 'inversify';
    import {GameService} from '../services';
    export class GameController extends BaseController {
      private service: GameService;
      constructor(bot: TelegramBot, private readonly gameService: GameService) {


    I have inherited a react project that uses inversify ioc. It all works well but I'm having trouble writing unit tests. I'm sure my issue is caused by a problem in my configuration somewhere.

    I'm getting this error when running the tests...

    constructor(@(0, _inversify.inject)(_ICookieStorage.ICookieStorageService$) ^
    SyntaxError: Invalid or unexpected token

    So it seems to me that it can't resolve the @inject in my constructor...

    @inject(ICookieStorageService$) cookieStorageService: ICookieStorageService,
    @inject(ILocalStorageService$) localStorageService: ILocalStorageService,
    @inject(ISessionStorageService$) sessionStorageService: ISessionStorageService
    ) {
    ...code here

    In the root index.ts of my application, I wrap the application in

    import { Provider } from 'inversify-react';

    <Provider container={container}>
    ...the app

    and container is defined in inversify.config.ts.

    Obviously this doesn't get wired up when running tests. I'm not sure how to fix my issue. There is almost zero information out there on unit testing with inversify.

    I've tried putting import 'reflect-metadata'; everywhere. That didn't help. Also, I don't use babel.

    Please help.