A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.

Overview

InversifyJS

Join the chat at https://gitter.im/inversify/InversifyJS Build Status

Test Coverage npm version Dependencies img img Known Vulnerabilities Twitter Follow

NPM NPM

A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.

About

InversifyJS is a lightweight inversion of control (IoC) container for TypeScript and JavaScript apps. An IoC container uses a class constructor to identify and inject its dependencies. InversifyJS has a friendly API and encourages the usage of the best OOP and IoC practices.

Motivation

JavaScript now supports object oriented (OO) programming with class based inheritance. These features are great but the truth is that they are also dangerous.

We need a good OO design (SOLID, Composite Reuse, etc.) to protect ourselves from these threats. The problem is that OO design is difficult and that is exactly why we created InversifyJS.

InversifyJS is a tool that helps JavaScript developers write code with good OO design.

Philosophy

InversifyJS has been developed with 4 main goals:

  1. Allow JavaScript developers to write code that adheres to the SOLID principles.

  2. Facilitate and encourage the adherence to the best OOP and IoC practices.

  3. Add as little runtime overhead as possible.

  4. Provide a state of the art development experience.

Testimonies

Nate Kohari - Author of Ninject

"Nice work! I've taken a couple shots at creating DI frameworks for JavaScript and TypeScript, but the lack of RTTI really hinders things. The ES7 metadata gets us part of the way there (as you've discovered). Keep up the great work!"

Michel Weststrate - Author of MobX

Dependency injection like InversifyJS works nicely

Some companies using InversifyJS

Installation

You can get the latest release and the type definitions using npm:

$ npm install inversify reflect-metadata --save

The InversifyJS type definitions are included in the inversify npm package.

⚠️ Important! InversifyJS requires TypeScript >= 2.0 and the experimentalDecorators, emitDecoratorMetadata, types and lib compilation options in your tsconfig.json file.

{
    "compilerOptions": {
        "target": "es5",
        "lib": ["es6"],
        "types": ["reflect-metadata"],
        "module": "commonjs",
        "moduleResolution": "node",
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true
    }
}

InversifyJS requires a modern JavaScript engine with support for:

If your environment doesn't support one of these you will need to import a shim or polyfill.

⚠️ The reflect-metadata polyfill should be imported only once in your entire application because the Reflect object is meant to be a global singleton. More details about this can be found here.

Check out the Environment support and polyfills page in the wiki and the Basic example to learn more.

The Basics

Let’s take a look at the basic usage and APIs of InversifyJS with TypeScript:

Step 1: Declare your interfaces and types

Our goal is to write code that adheres to the dependency inversion principle. This means that we should "depend upon Abstractions and do not depend upon concretions". Let's start by declaring some interfaces (abstractions).

// file interfaces.ts

export interface Warrior {
    fight(): string;
    sneak(): string;
}

export interface Weapon {
    hit(): string;
}

export interface ThrowableWeapon {
    throw(): string;
}

InversifyJS needs to use the type as identifiers at runtime. We use symbols as identifiers but you can also use classes and or string literals.

// file types.ts

const TYPES = {
    Warrior: Symbol.for("Warrior"),
    Weapon: Symbol.for("Weapon"),
    ThrowableWeapon: Symbol.for("ThrowableWeapon")
};

export { TYPES };

Note: It is recommended to use Symbols but InversifyJS also support the usage of Classes and string literals (please refer to the features section to learn more).

Step 2: Declare dependencies using the @injectable & @inject decorators

Let's continue by declaring some classes (concretions). The classes are implementations of the interfaces that we just declared. All the classes must be annotated with the @injectable decorator.

When a class has a dependency on an interface we also need to use the @inject decorator to define an identifier for the interface that will be available at runtime. In this case we will use the Symbols Symbol.for("Weapon") and Symbol.for("ThrowableWeapon") as runtime identifiers.

// file entities.ts

import { injectable, inject } from "inversify";
import "reflect-metadata";
import { Weapon, ThrowableWeapon, Warrior } from "./interfaces";
import { TYPES } from "./types";

@injectable()
class Katana implements Weapon {
    public hit() {
        return "cut!";
    }
}

@injectable()
class Shuriken implements ThrowableWeapon {
    public throw() {
        return "hit!";
    }
}

@injectable()
class Ninja implements Warrior {

    private _katana: Weapon;
    private _shuriken: ThrowableWeapon;

    public constructor(
	    @inject(TYPES.Weapon) katana: Weapon,
	    @inject(TYPES.ThrowableWeapon) shuriken: ThrowableWeapon
    ) {
        this._katana = katana;
        this._shuriken = shuriken;
    }

    public fight() { return this._katana.hit(); }
    public sneak() { return this._shuriken.throw(); }

}

export { Ninja, Katana, Shuriken };

If you prefer it you can use property injection instead of constructor injection so you don't have to declare the class constructor:

@injectable()
class Ninja implements Warrior {
    @inject(TYPES.Weapon) private _katana: Weapon;
    @inject(TYPES.ThrowableWeapon) private _shuriken: ThrowableWeapon;
    public fight() { return this._katana.hit(); }
    public sneak() { return this._shuriken.throw(); }
}

Step 3: Create and configure a Container

We recommend to do this in a file named inversify.config.ts. This is the only place in which there is some coupling. In the rest of your application your classes should be free of references to other classes.

// file inversify.config.ts

import { Container } from "inversify";
import { TYPES } from "./types";
import { Warrior, Weapon, ThrowableWeapon } from "./interfaces";
import { Ninja, Katana, Shuriken } from "./entities";

const myContainer = new Container();
myContainer.bind<Warrior>(TYPES.Warrior).to(Ninja);
myContainer.bind<Weapon>(TYPES.Weapon).to(Katana);
myContainer.bind<ThrowableWeapon>(TYPES.ThrowableWeapon).to(Shuriken);

export { myContainer };

Step 4: Resolve dependencies

You can use the method get<T> from the Container class to resolve a dependency. Remember that you should do this only in your composition root to avoid the service locator anti-pattern.

import { myContainer } from "./inversify.config";
import { TYPES } from "./types";
import { Warrior } from "./interfaces";

const ninja = myContainer.get<Warrior>(TYPES.Warrior);

expect(ninja.fight()).eql("cut!"); // true
expect(ninja.sneak()).eql("hit!"); // true

As we can see the Katana and Shuriken were successfully resolved and injected into Ninja.

InversifyJS supports ES5 and ES6 and can work without TypeScript. Head to the JavaScript example to learn more!

The InversifyJS Features and API

Let's take a look to the InversifyJS features!

Please refer to the wiki for additional details.

Ecosystem

In order to provide a state of the art development experience we are also working on:

Please refer to the ecosystem wiki page to learn more.

Support

If you are experience any kind of issues we will be happy to help. You can report an issue using the issues page or the chat. You can also ask questions at Stack overflow using the inversifyjs tag.

If you want to share your thoughts with the development team or join us you will be able to do so using the official the mailing list. You can check out the wiki to learn more about InversifyJS internals.

Acknowledgements

Thanks a lot to all the contributors, all the developers out there using InversifyJS and all those that help us to spread the word by sharing content about InversifyJS online. Without your feedback and support this project would not be possible.

License

License under the MIT License (MIT)

Copyright © 2015-2017 Remo H. Jansen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.

IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Promise (Lazy) Support + Global onActivation/onDeactivation

    Promise (Lazy) Support + Global onActivation/onDeactivation

    This is a cleaner refactor which combines #1074 and #1086 to allow for users to opt-in to lazy loaded dependencies by using an asynchronous API.

    For anyone wanting to play around with this, you can use the NPM release:

    @parisholley/inversify-async:1.1.7

    Description

    New container methods for pulling objects out of the container in an asynchronous fashion while respecting container semantics and error if trying to mix synchronous/asynchronous dependencies.

    Implementation

    container.bind<Type>('name').toDynamicValue(async () => {
      return await myAsyncFunction();
    });
    container.bind<string>('resolve').toDynamicValue(() => Promise.resolve('foobar'));
    
    const value = await container.getAsync<Type>('name'); // result of myAsyncFunction
    const value = await container.get<Type>('name'); // throws an exception
    const value = await container.getAsync<string>('resolve'); // foobar
    

    Global onActivation

    container.onActivation('asyncIdentifier', (context, injectable) => {
      return Promise.resolve('newObject'); // returning a promise enforces use of getAsync(), even if future binds are not async
    });
    container.bind('asyncIdentifier').toConstantValue('foobar');
    
    await container.getAsync('asyncIdentifier');
    
    container.onActivation('syncIdentifier', (context, injectable) => {
      return 'newObject'; // no promise = use legacy API
    });
    
    container.get('syncIdentifier');
    

    Binding onActivation

    container.bind('asyncIdentifier').toConstantValue('foobar').onActivation((context, injectable) => {
      return Promise.resolve('newObject'); // returning a promise enforces use of getAsync()
    });
    
    await container.getAsync('asyncIdentifier');
    
    container.bind('asyncIdentifier').toConstantValue('foobar').onActivation((context, injectable) => {
      return 'newObject'; // no promise = use legacy API
    });
    
    container.get('syncIdentifier');
    

    Parent/Child onActivation

    container.onActivation('asyncIdentifier', (context, injectable) => {
      return Promise.resolve('newObject'); // returning a promise enforces use of getAsync()
    });
    
    const child = container.createChild();
    child.bind('asyncIdentifier').toConstantValue('foobar');
    
    await container.getAsync('asyncIdentifier');
    

    Module onActivation

    container.bind('asyncIdentifier').toConstantValue('foobar');
    
    const TestContainerModule = new ContainerModule((bind, unbind, isBound, rebind, onActivation) => {
      onActivation('asyncIdentifier', async (context, service) => {
    
     }));
    });
    

    Related Issue

    #418 #475 #887 #404

    Motivation and Context

    Use Case 1: Unit/System Testing While you technically could create separate containers (with a parent container for common objects) for a unit test environment and system test (database, etc), it adds more code complexity and also requires each system integration be live and working in order to bootstrap the container (this matters, because for instance in the IDE, if I want to run a single test, with a single I/O dependency, I don't have to initiate every connection).

    Use Case 2: Common Container Use Let's say you have a "service" code base that is re-used between a web application, command line interface and batch processing. In the case of the CLI, you have different commands that serve different purpose, eg:

    • Clone production data
    • Invoke third party service

    By making I/O dependencies lazy loaded (async), our CLI can wait until runtime to connect to the system that it needs for the task (otherwise, same problem as above, you are forced to connect-to, and have access-to systems that are unrelated to the command at hand).

    Use Case 3: Transactions: For testing (or perhaps a custom request based framework where child containers are created for each web request to implement "Request Scope" similar to spring), it may be useful to have async construct/destroy methods. For example, a web request where we want to run all service calls in a transaction and commit on at the end (by unbinding the container), or in tests by rolling back database changes for more performant runs.

    How Has This Been Tested?

    Full suite of tests have been implemented.

    Types of changes

    • [x] Updated docs / Refactor code / Added a tests case (non-breaking change)
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist:

    • [x] My code follows the code style of this project.
    • [x] My change requires a change to the documentation.
    • [x] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [x] I have added tests to cover my changes.
    • [x] All new and existing tests passed.
    • [x] I have updated the changelog.
    opened by parisholley 106
  • Update typescript compiler options

    Update typescript compiler options

    Description

    This PR aims to update Typescript version and add strict compiler options

    Related Issue

    #1222, #1271

    Motivation and Context

    We should try to use Typescript strict options in our project. This would help us to detect some typing issues such as #1222, which would have been detected.

    How Has This Been Tested?

    • All tests passes successfully

    Types of changes

    • [x] Updated docs / Refactor code / Added a tests case (non-breaking change)
    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist:

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [ ] I have added tests to cover my changes.
    • [x] All new and existing tests passed.
    • [ ] I have updated the changelog.
    opened by notaphplover 56
  • Allow multiple tags while resolving values

    Allow multiple tags while resolving values

    Description

    This change extends the getTagged, isBoundTagged, getAllTagged, getTaggedAsync and getAllTaggedAsync to accept multiple tags while resolving the dependency. The functionality was already implemented but not exposed in those methods.

    The solution here was to just accept tuples of [key: symbol | string | number, value: any] in those methods and covert them into Metadata instances while building the plan.

    Related Issue

    Closes #1110

    Motivation and Context

    This gives more power while registering instances and resolving them. This is particularly useful when building factories.

    How Has This Been Tested?

    This change is covered in unit testing.

    Types of changes

    • [ ] Updated docs / Refactor code / Added a tests case (non-breaking change)
    • [ ] Bug fix (non-breaking change which fixes an issue)
    • [x] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist:

    • [x] My code follows the code style of this project.
    • [x] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [x] I have added tests to cover my changes.
    • [x] All new and existing tests passed.
    • [ ] I have updated the changelog.
    opened by luiz290788 32
  • [inversify-restify-utils]: new release due to security vuln in dependency

    [inversify-restify-utils]: new release due to security vuln in dependency

    For inversify-restify-utils: Due to a security vulnerability in the dependency "csv" (see here) would be nice to create a release of the current master branch version.

    The current master branch version updates the restify dependency, which already supports the new fixed "csv" version 5.1.3. But unfortunately there is no release for this.

    Expected Behavior

    New Release version with the fixed dependency.

    Current Behavior

    There is no current release version with the updated dependency.

    Possible Solution

    Release a new version with the current master branch

    opened by Pekery 31
  • Restify and Express utils hang if there's a thrown error in the controller

    Restify and Express utils hang if there's a thrown error in the controller

    If an error is thrown inside the controller, the route is never resolved. This results in the route never being resolved.

    Expected Behavior

    I'd expect for the error to resolved as an error up the callback chain

    Current Behavior

    The route is never resolved

    Possible Solution

    Wrap in a try/catch and resolve the callback/

    Steps to Reproduce (for bugs)

    1. Create controller
    2. Add throw new Error('some error') as the first line
    3. Hit the endpoint in your browser

    Context

    This is a problem in production in case something throws an error and it'll cause a bottleneck.

    Your Environment

    • Version used: 2.1.2 (restify) 2.0.2 (express)
    • Environment name and version: Node 6
    • Operating System and version: OSX

    Stack trace

    None

    side-project express-utils 
    opened by mrsimonemms 29
  • Update updates to the latest version 🚀

    Update updates to the latest version 🚀

    The devDependency updates was updated from 8.5.3 to 9.0.0.

    This version is not covered by your current version range.

    If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.


    Publisher: silverwind License: BSD-2-Clause

    Find out more about this release.


    FAQ and help

    There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


    Your Greenkeeper bot :palm_tree:

    greenkeeper 
    opened by greenkeeper[bot] 24
  • Discussion: Node web framework

    Discussion: Node web framework

    We are thinking that express-utils is likely to become a full framework. We are going to use this issue to share ideas and feature requests.

    We have already identified support for authorisation as a required feature.

    discussion side-project express-utils 
    opened by remojansen 23
  • docs: how to create factory with different scope

    docs: how to create factory with different scope

    Description

    Allow to change toFactory scope;

    Related Issue

    https://github.com/inversify/InversifyJS/issues/1439

    Motivation and Context

    https://github.com/inversify/InversifyJS/issues/1439

    How Has This Been Tested?

    Types of changes

    • [ ] Updated docs / Refactor code / Added a tests case (non-breaking change)
    • [x] Bug fix (non-breaking change which fixes an issue)
    • [ ] New feature (non-breaking change which adds functionality)
    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    Checklist:

    • [x] My code follows the code style of this project.
    • [ ] My change requires a change to the documentation.
    • [ ] I have updated the documentation accordingly.
    • [x] I have read the CONTRIBUTING document.
    • [x] I have added tests to cover my changes.
    • [x] All new and existing tests passed.
    • [ ] I have updated the changelog.
    opened by Ayzrian 20
  • I can't get this work with my current TypeScript 2.3 project

    I can't get this work with my current TypeScript 2.3 project

    I would love to use this in my project. But it seems to blow up when im trying to install it

    • I am using webpack
    • I have TypeScript 2.3
    • I am using react
    • My @Types folder is inside a top level node_modules@Types folder alt text

    And this is where the types that I EXCPLICTITY installed via command line like npm install --save @types/react live

    alt text

    My setup that works

    So before I installed Inversify 2.0, everything was working very well.

    I had this tsconfig.json file

      "compilerOptions": {
        "allowSyntheticDefaultImports": true,
        "moduleResolution": "node",
        "outDir": "./dist/",
        "sourceMap": true,
        "noImplicitAny": false,
        "module": "es2015",
        "target": "es5",
        "jsx": "react",
        "types" : ["jquery", "lodash", "react", "react-dom"]
      },
        "include": [
            "./src/**/*"
        ]
    }
    

    And this package.json

      "name": "task1webpackconfig",
      "version": "1.0.0",
      "description": "webpack 2 + TypeScript 2 + Babel example",
      "repository": {
        "type": "git",
        "url": "git+https://github.com/sachabarber/MadCapIdea.git"
      },
      "keywords": [
        "babel",
        "typescript",
        "webpack",
        "bundling",
        "javascript",
        "npm"
      ],
      "author": "sacha barber",
      "homepage": "https://github.com/sachabarber/MadCapIdea#readme",
      "dependencies": {
        "bootstrap": "^3.3.7",
        "jquery": "^3.2.1",
        "lodash": "^4.17.4",
        "react": "^15.5.4",
        "react-bootstrap": "^0.31.0",
        "react-dom": "^15.5.4",
        "webpack": "^2.5.0",
        "webpack-merge": "^4.1.0"
      },
      "devDependencies": {
        "@types/jquery": "^2.0.43",
        "@types/lodash": "^4.14.63",
        "@types/react": "^15.0.24",
        "@types/react-dom": "^15.5.0",
        "awesome-typescript-loader": "^3.1.3",
        "babel-core": "^6.24.1",
        "babel-loader": "^7.0.0",
        "babel-preset-es2015": "^6.24.1",
        "babel-preset-es2015-native-modules": "^6.9.4",
        "babel-preset-react": "^6.24.1",
        "css-loader": "^0.28.1",
        "extract-text-webpack-plugin": "^2.1.0",
        "html-webpack-plugin": "^2.28.0",
        "node-sass": "^4.5.2",
        "on-build-webpack": "^0.1.0",
        "sass-loader": "^6.0.3",
        "source-map-loader": "^0.2.1",
        "typescript": "^2.3.2",
        "webpack": "^2.4.1"
      },
      "scripts": {
        "build-dev": "webpack -d --config webpack.develop.js",
        "build-prod": "webpack --config webpack.production.js"
      }
    }
    

    So then I followed instructions here : https://github.com/inversify/InversifyJS#installation

    So for me that meant doing the following

    1. Installing : npm install inversify reflect-metadata --save
    2. Adding/modofying the following to my tsconfig.json file
    lib": ["es6"],
    "types": ["reflect-metadata"],
    "module": "commonjs",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
    

    As I say my setup has a top level node_modules folder with @Types inside it. After installing inversify I Don't see any additional types added in the node_modules@Types folder , even though I believe inversify (The InversifyJS type definitions are included in the inversify npm package.)

    So when I then run this new setup. I get a tonne of errors from the webpack command line.

    Loads of line starting with this sort of thing error in [at-loader]

    My setup was working without these changes for inversify, although I should point out that it is not able to find typing information for installed types for other things either, it does however work completely fine at runtime.

    I have raised a StackOverflow for that : http://stackoverflow.com/questions/43789778/webpack-typescript-react-module-not-found

    I should point out I am new to Typescript/Webpack, but any help would be greatly appreciated

    opened by sachabarber 20
  • 2.0 release progress

    2.0 release progress

    Hi @inversify/collaborators, is there any news on the release progress of 2.0.0-alpha.0?

    It would be good to get working again towards the roadmap! :fireworks: :smile:

    discussion 
    opened by Jameskmonger 19
  • Using inversify-express-utils, how can i integrate websockets?

    Using inversify-express-utils, how can i integrate websockets?

    From SO:

    http://stackoverflow.com/questions/40612963/using-inversify-express-utils-how-can-i-integrate-websockets

    cc: @codyjs this is not supported right? would it be hard to implement?

    opened by remojansen 18
  • Guidance on using InversifyJS with bundlers and build tools that don't support `emitDecoratorMetadata`

    Guidance on using InversifyJS with bundlers and build tools that don't support `emitDecoratorMetadata`

    The readme states:

    ⚠️ Important! InversifyJS requires TypeScript >= 4.4 and the experimentalDecorators, emitDecoratorMetadata, types and lib compilation options in your tsconfig.json file.

    It is a common scenario in web apps to use a bundler (Webpack, Rollup, ESbuild, etc.), either configured manually or through pre-configured dev environments (Vite, create-react-app), which may use a transpiler (Babel, SWC).

    Most or all of these tools have limitations in what they can do with TypeScript. ESbuild acknowledges it's lack of support for emitDecoratorMetadata:

    The emitDecoratorMetadata TypeScript configuration option is not supported. This feature passes a JavaScript representation of the corresponding TypeScript type to the attached decorator function. Since esbuild does not replicate TypeScript's type system, it does not have enough information to implement this feature.

    I know Babel is partially or fully capable of working around this limitation with various plugins.

    The questions I hope to have answers to (preferably in the InversifyJS docs) are:

    1. What limitations are acknowledged for projects using build tools besides tsc?
    2. Do these limitations prevent the use of InversifyJS altogether, or just prevent the use of certain features? The Support for classes documentation does touch on this a bit.
    opened by zzzachzzz 0
  • fix: include source-map related files

    fix: include source-map related files

    fix: include source-map related files

    Description

    In Wepack5+, deps using source map but published exclude those files will receive lots of warnings.

    Related Issue

    Motivation and Context

    this PR will publish required files which will prevent developers using webpack5 annoyed by source map warnings.

    Types of changes

    • [ ] Updated docs / Refactor code / Added a tests case (non-breaking change)

    • [x] Bug fix (non-breaking change which fixes an issue)

    • [ ] New feature (non-breaking change which adds functionality)

    • [ ] Breaking change (fix or feature that would cause existing functionality to change)

    • [x] My code follows the code style of this project.

    • [x] My change requires a change to the documentation.

    • [x] I have updated the documentation accordingly.

    • [x] I have read the CONTRIBUTING document.

    • [x] I have added tests to cover my changes.

    • [x] All new and existing tests passed.

    • [x] I have updated the changelog.

    opened by ObservedObserver 0
  • @injectable() in abstract class doesn't work with protected constructor

    @injectable() in abstract class doesn't work with protected constructor

    Decorator function return type 'abstract new (...args: never) => unknown' is not assignable to type 'void | typeof BaseController'.
      Types of construct signatures are incompatible.
        Type 'abstract new (...args: never) => unknown' is not assignable to type 'abstract new (logger: ILogger) => BaseController'.
          Type 'unknown' is not assignable to type 'BaseController'.ts(1270)
    Argument of type 'typeof BaseController' is not assignable to parameter of type 'abstract new (...args: never) => unknown'.
      Cannot assign a 'protected' constructor type to a 'public' constructor type.ts(2345)
    

    This error rise when I make constructor protected, I'm trying to find answer in Inversify docs but where is nothing about

    Example of my code

    @injectable()
    export abstract class BaseController {
        private readonly _router: Router
    
        protected constructor(@inject(TYPES.ILogger) private logger: ILogger) {
            this._router = Router();
        }
        //some code
    }
    
    

    Why should it be public?

    opened by AmirBazanov 0
  • Bump decode-uri-component from 0.2.0 to 0.2.2

    Bump decode-uri-component from 0.2.0 to 0.2.2

    Bumps decode-uri-component from 0.2.0 to 0.2.2.

    Release notes

    Sourced from decode-uri-component's releases.

    v0.2.2

    • Prevent overwriting previously decoded tokens 980e0bf

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.1...v0.2.2

    v0.2.1

    • Switch to GitHub workflows 76abc93
    • Fix issue where decode throws - fixes #6 746ca5d
    • Update license (#1) 486d7e2
    • Tidelift tasks a650457
    • Meta tweaks 66e1c28

    https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.1

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • [inversify-restify-utils] package does not work with node 18 because of outdated dependency

    [inversify-restify-utils] package does not work with node 18 because of outdated dependency

    I would like for inversify-restify-utils to update its dependency on restify to allow for projects that use it to work in node@18

    (I am willing to create a PR)

    Expected Behavior

    Upgrade to node@18 and restify@10 and for my app to run correctly.

    Current Behavior

    My app does not run in node@18 because of inversify-restify-utils since it depends on a version of restify that does not work with node@18 (i.e. restify < v10)

    Possible Solution

    1. update the restify dependency to version 10 with a major version update.
    2. if this is gonna be a major version update anyway why not go the route of restify-swagger-jsdoc and set restify as a peerDependency >= 10 to avoid similar issues in the future?

    Steps to Reproduce (for bugs)

    1. create a node app using node@18 and restify@10
    2. install inversify-restify-utils@latest
    3. run the app

    Context

    We want to use node@18 in our app at work however this package is blocking us from doing so.

    Your Environment

    • Version used: [email protected]
    • Environment name and version (e.g. Chrome 39, node.js 5.4): node@18 and Chrome 107
    • Operating System and version (desktop or mobile): macOS 12.6
    • Link to your project:

    Stack trace

    (known issue with restify < v10)

    TypeError: Cannot set property closed of #<Readable> which has only a getter
        at patch (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/inversify-restify-utils/node_modules/restify/lib/request.js:848:30)
        at Object.<anonymous> (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/inversify-restify-utils/node_modules/restify/lib/server.js:33:1)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Object.require.extensions.<computed> [as .js] (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/ts-node/src/index.ts:1608:43)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Function.Module._load (node:internal/modules/cjs/loader:878:12)
        at Module.require (node:internal/modules/cjs/loader:1061:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.<anonymous> (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/inversify-restify-utils/node_modules/restify/lib/index.js:10:14)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Object.require.extensions.<computed> [as .js] (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/ts-node/src/index.ts:1608:43)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Function.Module._load (node:internal/modules/cjs/loader:878:12)
        at Module.require (node:internal/modules/cjs/loader:1061:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.<anonymous> (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/inversify-restify-utils/lib/server.js:22:17)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Object.require.extensions.<computed> [as .js] (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/ts-node/src/index.ts:1608:43)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Function.Module._load (node:internal/modules/cjs/loader:878:12)
        at Module.require (node:internal/modules/cjs/loader:1061:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.<anonymous> (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/inversify-restify-utils/lib/index.js:4:16)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Object.require.extensions.<computed> [as .js] (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/ts-node/src/index.ts:1608:43)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Function.Module._load (node:internal/modules/cjs/loader:878:12)
        at Module.require (node:internal/modules/cjs/loader:1061:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.<anonymous> (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/tests/unit/AppTest.ts:11:1)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module.m._compile (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/ts-node/src/index.ts:1618:23)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Object.require.extensions.<computed> [as .ts] (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/ts-node/src/index.ts:1621:12)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Function.Module._load (node:internal/modules/cjs/loader:878:12)
        at Module.require (node:internal/modules/cjs/loader:1061:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.exports.requireOrImport (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/mocha/lib/nodejs/esm-utils.js:49:16)
        at async Object.exports.loadFilesAsync (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/mocha/lib/nodejs/esm-utils.js:91:20)
        at async singleRun (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/mocha/lib/cli/run-helpers.js:125:3)
        at async Object.exports.handler (/Users/alessandro.commodari/ssense/workspace/services/ag-shipping/node_modules/mocha/lib/cli/run.js:370:5)
    
    opened by acommodari 4
  • Inversify-express-utils release to match Readme?

    Inversify-express-utils release to match Readme?

    I was trying to follow the directions for using a Principal from the Readme of the inversify-express-utils and after struggling finally realized that the Readme is not in sync with the current release. Principal was made a generic back in March but there has not been a new package release. I was wondering when the next release of that package was going to occur.

    My project is setup to not allow use of any and having a generic principal would fit the bill.

    opened by rcollette 0
Releases(v6.0.1)
  • v6.0.1(Oct 14, 2021)

    Added

    • add API method for check dependency only in current container
    • createTaggedDecorator #1343
    • Async bindings #1132
    • Async binding resolution (getAllAsync, getAllNamedAsync, getAllTaggedAsync, getAsync, getNamedAsync, getTaggedAsync, rebindAsync, unbindAsync, unbindAllAsync, unloadAsync) #1132
    • Global onActivation / onDeactivation #1132
    • Parent/Child onActivation / onDeactivation #1132
    • Module onActivation / onDeactivation #1132
    • Added @preDestroy decorator #1132

    Changed

    • @postConstruct can target an asyncronous function #1132
    • Singleton scoped services cache resolved values once the result promise is fulfilled #1320

    Fixed

    • only inject decorator can be applied to setters #1342
    • Container.resolve should resolve in that container #1338
    Source code(tar.gz)
    Source code(zip)
  • 5.1.0(Apr 25, 2021)

    Added

    • Upgrade information for v4.x to v5.x

    Fixed

    • Fix Target.isTagged() to exclude optional from tag injections #1190.
    • Update toConstructor, toFactory, toFunction, toAutoFactory, toProvider and toConstantValue to have singleton scope #1297.
    • Fix injection on optional properties when targeting ES6 #928
    Source code(tar.gz)
    Source code(zip)
  • 5.0.3(Jul 6, 2020)

  • 4.11.1(Feb 26, 2018)

  • 4.11.0(Feb 26, 2018)

  • 4.5.1(Nov 4, 2017)

    • Fix: allows to use inRequestScope as default scope using container config
    • Fix: it is able to detect circular dependencies even when using factories
    Source code(tar.gz)
    Source code(zip)
  • 4.5.0(Nov 2, 2017)

  • 4.4.0(Oct 31, 2017)

  • 4.3.0(Jul 24, 2017)

    Commits

    @remojansen Create CODE_OF_CONDUCT.md (#594) c756c7f @AltekkeE Travis tests are failing due to latest update to tslint #602 (#603) 1bdb3ac @theodesp Issue-605 Documented @postConstruct Decorator (#608) 7c9e83c @sanex3339 Fixes issue #615 (#616) 11109c5 @theodesp Issue-612 Fixed typos all over the codebase. Tests still pass. (#613) c944009 @tiagoschenkel isBound, isBoundNamed and isBoundTagged methods are checking ancestors 3a712d7

    Source code(tar.gz)
    Source code(zip)
  • 4.2.0(Jul 2, 2017)

    Commits

    @remojansen Fixing build (#578) 14f36fe @remojansen Update README.md 75dd911 @greenkeeper update del to version 3.0.0 (#580) fa442ff @AltekkeE Added @postConstruct method decorator (#588) c822d75 @AltekkeE VS Code mocha debugging (#589) dff05d4 @greenkeeper Update run-sequence to version 2.0.0 (#591) b4d66aa @remojansen Update dependencies (#592) 67f2a39

    Source code(tar.gz)
    Source code(zip)
  • 4.1.1(May 30, 2017)

    @greenkeeper update gulp-mocha to version 4.3.1 (#547) … f888d44 @remojansen remojansen Implements #546 081929d @remojansen remojansen Update readme.md 24b2882 @remojansen remojansen Update injecting_npm_modules.md 6068dc4 @remojansen remojansen Update injecting_npm_modules.md 86e41d7 @greenkeeper update gulp-uglify to version 3.0.0 (#555) 8f337a4 @remojansen remojansen Fixes issue #559 …

    Source code(tar.gz)
    Source code(zip)
  • 4.1.0(Apr 25, 2017)

  • 4.0.0(Apr 24, 2017)

    Breaking changes

    There is a breaking change in this release. The change is likely to affect a very small group of users but it is a breaking change which explains why this release is 4.0.0.

    The breaking change is caused by a fix in a typo in a public API:

    The public method getConstrucotorMetadata is now getConstructorMetadata:

    interface MetadataReader {
         getConstrucotorMetadata(constructorFunc: Function): ConstructorMetadata;
         getPropertiesMetadata(constructorFunc: Function): MetadataMap;
    }
    

    Is now:

    interface MetadataReader {
         getConstructorMetadata(constructorFunc: Function): ConstructorMetadata;
         getPropertiesMetadata(constructorFunc: Function): MetadataMap;
    }
    

    Commits

    @greenkeeper update tslint to version 5.0.0 (#519) … 0c14e57 @greenkeeper update @types/sinon to version 2.1.0 (#518) … 17e4541 @remojansen remojansen Add some test cases & solve coverage issues (#538) … 7a6a60e @remojansen remojansen Fixes typo in public API #536 (#539) 93f83c2 @greenkeeper Update gulp-tslint to the latest version :rocket: (#529) … 52596e0 @remojansen remojansen Added test case for #528 (#540) … 3553c79

    Source code(tar.gz)
    Source code(zip)
  • 3.3.0(Mar 22, 2017)

    This release adds support for #505 ad solves #497

    Commits

    @remojansen Implements #505 (#512) be1c2fc @remojansen Implements #497 (#513) 95c8f3a

    Source code(tar.gz)
    Source code(zip)
  • 3.2.0(Mar 21, 2017)

Owner
inversify
A powerful and lightweight inversion of control container for JavaScript & Node.js apps powered by TypeScript.
inversify
Package your Node.js project into an executable

Disclaimer: pkg was created for use within containers and is not intended for use in serverless environments. For those using Vercel, this means that

Vercel 22.6k Jan 7, 2023
browser-side require() the node.js way

browserify require('modules') in the browser Use a node-style require() to organize your browser code and load modules installed by npm. browserify wi

null 14.3k Dec 29, 2022
:red_circle: Functional task runner for Node.js

start ⚠️ Project has been transferred to NexTools metarepo functional – in all senses fast – parallelism and concurrency shareable – presets as publis

Kir Belevich 477 Dec 15, 2022
Build node packages into deployable applications

strong-build Build a node application package, preparing it for deploy to production. It is useful standalone, but is commonly used to build applicati

StrongLoop and IBM API Connect 47 Mar 3, 2022
Grunt: The JavaScript Task Runner

Grunt: The JavaScript Task Runner Documentation Visit the gruntjs.com website for all the things. Support / Contributing Before you make an issue, ple

grunt 12.2k Dec 31, 2022
Builder: A gulp-like build system with modern JavaScript

Builder: A gulp-like build system with modern JavaScript What is this? This is a build system meant to automate tasks. At this point it’s merely a con

Wladimir Palant 7 Mar 22, 2022
Creates ES6 ./index.js file in target directories that imports and exports all sibling files and directories.

create-index create-index program creates (and maintains) ES6 ./index.js file in target directories that imports and exports sibling files and directo

Gajus Kuizinas 270 Nov 25, 2022
Task toolkit. For when `npm run` isn't enough and everything else is too much.

For when npm run isn't enough and everything else is too much. Ygor is a no-frills toolkit consisting of a task runner and a file transformer. Enjoy a

Shannon Moeller 68 Nov 12, 2022
Simple build system and CLI for AMX Mod X projects

?? AMXXPack Simple build system and CLI for AMX Mod X projects. ?? About This system will be useful for projects with multiple plugins and assets. Usi

Hedgehog Fog 11 Nov 15, 2022
This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.

This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.

Keith 2 Jul 5, 2022
This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injection) + Primsa ORM + API REST boilerplate.

Express-TS-DDD REST API This is another Express + TypeScript + DDD (Domain Driven Design patterns) + IoC/DI (Inversion of control and Dependency injec

J.D. 6 Nov 3, 2022
A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control

Web Control for ZJU Fast-Drone-250 A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control (tested on Xiaomi

null 6 Nov 11, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Linux Remote This is a web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control. Do

Gabriel Guerra 4 Jul 6, 2022
Type Identity - a powerful and highly customizable authentication and authrozation and access-control framework

Type Identity is a powerful and highly customizable authentication and authrozation and access-control framework. It is the de-facto standard for securing Type Script api beta release

Saeed Mohammed Al-abidi 2 Jan 1, 2023
A powerful templating engine with inheritance, asynchronous control, and more (jinja2 inspired)

Nunjucks Nunjucks is a full featured templating engine for javascript. It is heavily inspired by jinja2. View the docs here. Installation npm install

Mozilla 8k Dec 30, 2022
Decorator-based service container for TypeScript

Capsule Lightweight TypeScript service container. Note: This is just quick preview of the documentation, not even alpha quality. For more detailed stu

Benjamin Beganović 4 Sep 26, 2022