Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Lautaro Cozzani
    it is in a early stage, but is fully functional, is pretty simple
    any comment, issue, PR or whatever are very welcome
    Garrett Scott

    Hello here, I’m using 4.13 and trying to use tagged bindings. I have something like


    Then I use the IClient in a parent class (`BooParent’) via

    class BooParent {
      constructor (@inject(“IClient”) private client: IClient) {}

    Then I to use that parent later via,

    @inject(“BooParent”) @named(“useFoo”) parent: BooParent;

    However, when I do something like that, I get no matching binding errors. Am I misunderstanding the named/tagged bindings, or is it probably just something in my setup somewhere?

    Garrett Scott
    just an update on :point_up: …it was my setup. I was doing a non-tagged injection in another place. So :thumbsup: , works!
    Harihara Krishnan

    need your kind help. I have my implementation like this

    interface IUserRepository<TModel>
    abstract class GenericRepository<TModel> implements IUserRepository<TModel>
    interface IUserRepository implements IRepository<UserModel>
    class UserRepository implements IUserRepository extends GenericRepository<UserModel>

    Where should I inject @injectible() and how should I bind in containers? kindly help

    I am trying to inject my userrepository in AuthController class
    Dennis Borisevich
    @vhhkrishnan_twitter place the annotation above UserRepository class. Will you refer to your UserRepository by it's interface or real class name in AuthController?

    Hey! I try to create a instance using Inversify, constructor contains a parameters like this @inject(IconsStore) private readonly store$: IconsStore,. In construtor, the store$ is avaiable, but if goes out the constructor, the class does not contain that and throws an error that is undefined. Does anyone know why?


        ["@babel/plugin-proposal-decorators", {
          "legacy": true
        ["@babel/plugin-proposal-class-properties", {
          "loose": true


     "@babel/core": "^7.5.5",
        "@babel/plugin-proposal-class-properties": "^7.5.5",
        "@babel/plugin-proposal-decorators": "^7.4.4",
        "@babel/plugin-syntax-dynamic-import": "^7.2.0",
        "@babel/plugin-transform-modules-commonjs": "^7.5.0",
        "@babel/plugin-transform-react-constant-elements": "^7.5.0",
        "@babel/preset-env": "^7.5.5",
        "@babel/preset-react": "^7.0.0",
        "@babel/preset-typescript": "^7.3.3",
        "reflect-metadata": "^0.1.13",
        "inversify": "^5.0.1",
        "inversify-inject-decorators": "^3.1.0",
    Dennis Borisevich
    @TheAifam5 Do you refer to it as this.store$ outside the constructor?
    the this is also empty
    export class GetSetService<T, S extends Store<T>, Q extends Query<T>> {
      public constructor(
        protected readonly store$: S,
        protected readonly query$: Q,
      ) {}
      public get<K extends keyof T>(prop: K): Observable<T[K]> {
        return this.query$.select(prop);
      public set<K extends keyof T>(prop: K, value: T[K]): void {
        this.store$.update(({ [prop]: value } as unknown) as Partial<T>);
    export class SettingsService extends GetSetService<SettingsModel, SettingsStore, SettingsQuery> {
      public constructor(
        store: SettingsStore,
        query: SettingsQuery,
      ) {
        super(store, query);
    Dennis Borisevich
    You mark store$ with @unmanaged() in GetSetService. Inversify will not inject those.
    I know. And I do not want to because is unable to determine the type in the "GetSetService".
    I'm getting only SettingsService, the GetSetService is just a base class
    that's why the SettingsService has @inject, which then SHOULD pass them to base class.
    or I'm doing something wrong here
    Dennis Borisevich
    Have you tried echoing this.store$ in GetSetService constructor? To see if it's getting set.
    yes, in the constructor store$ is not null, but this.store$ is null
    in the GetSetService
    Dennis Borisevich
    It looks like protected readonly part that is supposed to set your property in class is somehow not followed. Maybe outdated TS?
    I'm using babel to transpile TS, typescript is only for typing and IDE. Installed version is 3.5.3
    also all classes where I inject in constructor have that problem, another example:
    export class LaunchersService {
      public constructor(
        private readonly store: LaunchersStore,
        private readonly query: LaunchersQuery,
      ) {}
    Dennis Borisevich
    Can you please look at transpiled code to see if the property is set if it's declared as protected readonly or something like that?
    Harihara Krishnan
    @DenSpirit I achieved it. Appreciate your kindness. Thanks :). Have a great day!
    Bennett Dill
    InversifyJS looks perfect for adding IoC to my typescript project, but it looks like maybe its not getting updated anymore. Is it worth adopting at this point? Sorry, I don't mean to be rude with my question.
    Yannick Fricke

    Hey everyone! :)

    i have a short question:

    As you can see here I added the @injectable decorator to the plugin.

    I'm trying to write a server application which loads plugins (as you can see here).

    These plugins are transpiled seperatly.
    Inversify is throwing the error, that it cant find the @injectable annotation on my TestPlugin which definitely exists there.

    Error: Missing required @injectable annotation in: TestPlugin.

    When you define it twice, it says that the decorator is defined twice.

    Does someone has a hint for me? :)

    Yannick Fricke

    Got the source files packed (without node_modules)

    Install them in / and /plugins/TestPlugin
    Run the "build" script
    Then you have the transpiled files in the dist directory

    By the way: Very nice work! Used inversify for several projects! Its very nice to work with it :)
    Yannick Fricke

    Maybe I found a hint finally:


    But investigating it later. 3:30 am here :D

    Yannick Fricke
    Got it finally!
    At first I thought that ES5 is the issue (because the plugin was transpiled to that version) but i had another idea.
    Refactored the Plugin to be an interface (was an abstract class before).
    Then it worked.
    I dont even have to import reflect-metadata in the plugin - which is really nice :)
    Angel Angelov
    Hello! I am trying to build an npm package
    written in TypeScript
    to be used in a JavaScript app
    the exported entry point is a class, that receives an injected parameter in it's constructor
    in the JavaScript receiver that uses the package, how can I initialize this class?
    Is there a pattern for that?
    Matt Wills

    Hey guys, im using inversify-express-utils and im looking for a way to set an order for how my endpoints are matched.

    eg... using express.Router i could have


    and the users/me endpoint would resolve successfully.

    But using inversify, it seems like the users/me controller is being registered later, and so it's calling users/:userId with the userId param set to me instead.

    Is there a way to sort this? I can't see anything in the docs or on SO.


    Nat S
    hi, I have a question. I have DependencyContainer that binding my store. However, it seems lazyinject doesn't work if the component tried to call from constructor. Do you know how to fix it?
    Ruben Rutten

    I'm also really curious on how to solve the issue @mattwills8 is having for a project I'm working on now. I'm also wondering how to nest controllers. Using Express, I regularly have endpoints such as

    // routes/users/index.ts
    router.use("/:userId", (req, res, next) => {
      let user = getUserById(req.params.userId);
      req.vars.user = user;
    router.use("/:someId/posts", postsRouter);
    // routes/users/posts.ts
    router.get("/", (req, res) => {
      // access req.vars.user here

    Is it possible to nest controllers so that I can use the request chain to store context? If not, how should I achieve this

    Esakki Krishnan
    Is there a solution to "How to achieve component scanning/auto discovery of Controllers using Inversify + inversify-express-utils"
    Caleb Cushing
    is it possible to use @injectable on a method? for a 3rd party class that doesn't have @injectable on it, like a Spring @Bean
    Piotrek Paciorek
    I've run into a scenario where component exported from a react lib I work on, which has a bunch of classes decorated with @injectable, is being rendered on and off in an external react app. The first time the component appears in DOM everything works just fine, but after that, every attempt to render the component throws an error: Cannot apply @injectable decorator multiple times.. Is there a way to prevent inversify from re-decorating already decorated classes? I'm not really experienced with IoC in general and I quite ran out of ideas on how to solve this issue.
    Ondrej Synacek

    Hello, I'm trying to use Inversify for adding DI to express application. I want to create singleton of express app, so I came up with wrapper class

    import * as express from 'express'
    export default class ExpressAppFactory {
      private _express: express.Application
      public constructor() {
        this._express = express()
        return this._express

    and then I add it to container like this:


    This works but I'm getting type errors:

    [0] lib/services/express-app-factory.ts(10,5): error TS2409: Return type of constructor signature must be assignable to the instance type of the class.
    [0] lib/services/express-app-factory.ts(10,5): error TS2741: Property '_express' is missing in type 'Application' but required in type 'ExpressAppFactory'.

    Not sure if this is a way to go, I'm also pretty new to Typescript.

    Wilson Neto B.R.
    @comatory the construct cant return a instance of another class...
    Wilson Neto B.R.
    Guys, inversify-express-utils is a good chice to a big base of users?
    I am searching for a framework with IoC and one that I can use SOLID and DDD principles, are you using inversify-express in yours projetcts?
    Patryk Zajdler
    Hey guys, I'm having issues setting up my container, I'm using constructor injections and it's all there. Unfortunately I'm getting inject called with undefined error. I do not have any circular dependencies (checked with dependency-graphpackage)
    David Pohan
    Hello, I am using inversify-binding-decorators and having a blast, thanks for the awesome work!
    Although, I am having an issue. Is it possible to eager load a service?
    My services are annotated with @provide(Service) annotation. And then loaded using container.load(buildProviderModule())
    Now, it all works fine, but I have a service, that is not injected anywhere, and is used to subscribe to and handle events, emitted by another service that extends EventEmitter.
    The service is never loaded. Hence does not react to the emitted events.
    When I inject it somewhere, it gets loaded and starts reacting to the events.
    I have also tried providing the service in singleton scope, that has not worked neither.
    I am trying to avoid manually loading similar services that just handle events, and do not expose any public API.
    I searched but could not find anything about eager loading services. Is that possible?
    Thanks for the help in advance.
    David Pohan
    For now, I have worked around this issue, by eager loading all services:
    import { Container } from 'inversify';
    // Services, that do not expose any public API, hence are not used anywhere, have to be imported to get noticed by the provider module
    import { ProvisionService } from '../services/ProvisionService';
    export function eagerLoadAllServices(container: Container) {
        Array.from((container as any)._bindingDictionary._map.keys()).forEach(
            (identifier: any) => container.get(identifier),