Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

inversify

Package Overview
Dependencies
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inversify - npm Package Compare versions

Comparing version 4.3.0 to 4.4.0

4

amd/bindings/binding.js

@@ -5,7 +5,7 @@ define(["require", "exports", "../utils/guid", "../constants/literal_types"], function (require, exports, guid_1, literal_types_1) {

var Binding = (function () {
function Binding(serviceIdentifier, defaultScope) {
function Binding(serviceIdentifier, scope) {
this.guid = guid_1.guid();
this.activated = false;
this.serviceIdentifier = serviceIdentifier;
this.scope = defaultScope;
this.scope = scope;
this.type = literal_types_1.BindingTypeEnum.Invalid;

@@ -12,0 +12,0 @@ this.constraint = function (request) { return true; };

@@ -29,2 +29,4 @@ define(["require", "exports", "../utils/template"], function (require, exports, template_1) {

"be a string ('singleton' or 'transient').";
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
"be a boolean";
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";

@@ -31,0 +33,0 @@ exports.POST_CONSTRUCT_ERROR = (_a = ["@postConstruct error in class ", ": ", ""], _a.raw = ["@postConstruct error in class ", ": ", ""], template_1.template(_a, 0, 1));

@@ -10,10 +10,15 @@ define(["require", "exports", "../bindings/binding", "./lookup", "../planning/planner", "../resolution/resolver", "../syntax/binding_to_syntax", "../utils/serialization", "./container_snapshot", "../utils/guid", "../constants/error_msgs", "../constants/metadata_keys", "../constants/literal_types", "../planning/metadata_reader"], function (require, exports, binding_1, lookup_1, planner_1, resolver_1, binding_to_syntax_1, serialization_1, container_snapshot_1, guid_1, ERROR_MSGS, METADATA_KEY, literal_types_1, metadata_reader_1) {

}
else if (containerOptions.defaultScope === undefined) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
else {
if (containerOptions.defaultScope !== undefined &&
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
}
if (containerOptions.autoBindInjectable !== undefined &&
typeof containerOptions.autoBindInjectable !== "boolean") {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
}
}
else if (containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
}
this.options = {
autoBindInjectable: containerOptions.autoBindInjectable,
defaultScope: containerOptions.defaultScope

@@ -24,2 +29,3 @@ };

this.options = {
autoBindInjectable: false,
defaultScope: literal_types_1.BindingScopeEnum.Transient

@@ -109,5 +115,4 @@ };

Container.prototype.bind = function (serviceIdentifier) {
var defaultScope = literal_types_1.BindingScopeEnum.Transient;
defaultScope = (this.options.defaultScope === defaultScope) ? defaultScope : literal_types_1.BindingScopeEnum.Singleton;
var binding = new binding_1.Binding(serviceIdentifier, defaultScope);
var scope = this.options.defaultScope || literal_types_1.BindingScopeEnum.Transient;
var binding = new binding_1.Binding(serviceIdentifier, scope);
this._bindingDictionary.add(serviceIdentifier, binding);

@@ -114,0 +119,0 @@ return new binding_to_syntax_1.BindingToSyntax(binding);

@@ -18,5 +18,12 @@ define(["require", "exports", "./plan", "./context", "./request", "./target", "../bindings/binding_count", "./reflection_utils", "./metadata", "../constants/error_msgs", "../constants/metadata_keys", "../constants/literal_types", "../utils/serialization"], function (require, exports, plan_1, context_1, request_1, target_1, binding_count_1, reflection_utils_1, metadata_1, ERROR_MSGS, METADATA_KEY, literal_types_1, serialization_1) {

}
function _getActiveBindings(avoidConstraints, context, parentRequest, target) {
function _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target) {
var bindings = getBindings(context.container, target.serviceIdentifier);
var activeBindings = [];
if (bindings.length === binding_count_1.BindingCount.NoBindingsAvailable &&
context.container.options.autoBindInjectable &&
typeof target.serviceIdentifier === "function" &&
metadataReader.getConstructorMetadata(target.serviceIdentifier).compilerGeneratedMetadata) {
context.container.bind(target.serviceIdentifier).toSelf();
bindings = getBindings(context.container, target.serviceIdentifier);
}
if (avoidConstraints === false) {

@@ -68,3 +75,3 @@ activeBindings = bindings.filter(function (binding) {

if (parentRequest === null) {
activeBindings = _getActiveBindings(avoidConstraints, context, null, target);
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, null, target);
childRequest_1 = new request_1.Request(serviceIdentifier, context, null, activeBindings, target);

@@ -75,3 +82,3 @@ var thePlan = new plan_1.Plan(context, childRequest_1);

else {
activeBindings = _getActiveBindings(avoidConstraints, context, parentRequest, target);
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target);
childRequest_1 = parentRequest.addChildRequest(target.serviceIdentifier, activeBindings, target);

@@ -85,2 +92,5 @@ }

else {
if (binding.cache) {
return;
}
subChildRequest = childRequest_1;

@@ -87,0 +97,0 @@ }

@@ -16,5 +16,5 @@ import { interfaces } from "../interfaces/interfaces";

onActivation: ((context: interfaces.Context, injectable: T) => T) | null;
constructor(serviceIdentifier: interfaces.ServiceIdentifier<T>, defaultScope: interfaces.BindingScope);
constructor(serviceIdentifier: interfaces.ServiceIdentifier<T>, scope: interfaces.BindingScope);
clone(): interfaces.Binding<T>;
}
export { Binding };

@@ -22,3 +22,4 @@ export declare const DUPLICATED_INJECTABLE_DECORATOR = "Cannot apply @injectable decorator multiple times.";

export declare const CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE: string;
export declare const CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE: string;
export declare const MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
export declare const POST_CONSTRUCT_ERROR: (...values: any[]) => string;

@@ -131,3 +131,4 @@ declare namespace interfaces {

interface ContainerOptions {
defaultScope: BindingScope;
autoBindInjectable?: boolean;
defaultScope?: BindingScope;
}

@@ -134,0 +135,0 @@ interface Container {

import { guid } from "../utils/guid";
import { BindingTypeEnum } from "../constants/literal_types";
var Binding = (function () {
function Binding(serviceIdentifier, defaultScope) {
function Binding(serviceIdentifier, scope) {
this.guid = guid();
this.activated = false;
this.serviceIdentifier = serviceIdentifier;
this.scope = defaultScope;
this.scope = scope;
this.type = BindingTypeEnum.Invalid;

@@ -10,0 +10,0 @@ this.constraint = function (request) { return true; };

@@ -27,4 +27,6 @@ import { template } from "../utils/template";

"be a string ('singleton' or 'transient').";
export var CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
"be a boolean";
export var MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
export var POST_CONSTRUCT_ERROR = (_a = ["@postConstruct error in class ", ": ", ""], _a.raw = ["@postConstruct error in class ", ": ", ""], template(_a, 0, 1));
var _a;

@@ -19,10 +19,15 @@ import { Binding } from "../bindings/binding";

}
else if (containerOptions.defaultScope === undefined) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
else {
if (containerOptions.defaultScope !== undefined &&
containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
containerOptions.defaultScope !== BindingScopeEnum.Transient) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
}
if (containerOptions.autoBindInjectable !== undefined &&
typeof containerOptions.autoBindInjectable !== "boolean") {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
}
}
else if (containerOptions.defaultScope !== BindingScopeEnum.Singleton &&
containerOptions.defaultScope !== BindingScopeEnum.Transient) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
}
this.options = {
autoBindInjectable: containerOptions.autoBindInjectable,
defaultScope: containerOptions.defaultScope

@@ -33,2 +38,3 @@ };

this.options = {
autoBindInjectable: false,
defaultScope: BindingScopeEnum.Transient

@@ -118,5 +124,4 @@ };

Container.prototype.bind = function (serviceIdentifier) {
var defaultScope = BindingScopeEnum.Transient;
defaultScope = (this.options.defaultScope === defaultScope) ? defaultScope : BindingScopeEnum.Singleton;
var binding = new Binding(serviceIdentifier, defaultScope);
var scope = this.options.defaultScope || BindingScopeEnum.Transient;
var binding = new Binding(serviceIdentifier, scope);
this._bindingDictionary.add(serviceIdentifier, binding);

@@ -123,0 +128,0 @@ return new BindingToSyntax(binding);

@@ -25,5 +25,12 @@ import { Plan } from "./plan";

}
function _getActiveBindings(avoidConstraints, context, parentRequest, target) {
function _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target) {
var bindings = getBindings(context.container, target.serviceIdentifier);
var activeBindings = [];
if (bindings.length === BindingCount.NoBindingsAvailable &&
context.container.options.autoBindInjectable &&
typeof target.serviceIdentifier === "function" &&
metadataReader.getConstructorMetadata(target.serviceIdentifier).compilerGeneratedMetadata) {
context.container.bind(target.serviceIdentifier).toSelf();
bindings = getBindings(context.container, target.serviceIdentifier);
}
if (avoidConstraints === false) {

@@ -75,3 +82,3 @@ activeBindings = bindings.filter(function (binding) {

if (parentRequest === null) {
activeBindings = _getActiveBindings(avoidConstraints, context, null, target);
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, null, target);
childRequest_1 = new Request(serviceIdentifier, context, null, activeBindings, target);

@@ -82,3 +89,3 @@ var thePlan = new Plan(context, childRequest_1);

else {
activeBindings = _getActiveBindings(avoidConstraints, context, parentRequest, target);
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target);
childRequest_1 = parentRequest.addChildRequest(target.serviceIdentifier, activeBindings, target);

@@ -92,2 +99,5 @@ }

else {
if (binding.cache) {
return;
}
subChildRequest = childRequest_1;

@@ -94,0 +104,0 @@ }

@@ -6,7 +6,7 @@ "use strict";

var Binding = (function () {
function Binding(serviceIdentifier, defaultScope) {
function Binding(serviceIdentifier, scope) {
this.guid = guid_1.guid();
this.activated = false;
this.serviceIdentifier = serviceIdentifier;
this.scope = defaultScope;
this.scope = scope;
this.type = literal_types_1.BindingTypeEnum.Invalid;

@@ -13,0 +13,0 @@ this.constraint = function (request) { return true; };

@@ -29,4 +29,6 @@ "use strict";

"be a string ('singleton' or 'transient').";
exports.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE = "Invalid Container option. Auto bind injectable must " +
"be a boolean";
exports.MULTIPLE_POST_CONSTRUCT_METHODS = "Cannot apply @postConstruct decorator multiple times in the same class";
exports.POST_CONSTRUCT_ERROR = (_a = ["@postConstruct error in class ", ": ", ""], _a.raw = ["@postConstruct error in class ", ": ", ""], template_1.template(_a, 0, 1));
var _a;

@@ -21,10 +21,15 @@ "use strict";

}
else if (containerOptions.defaultScope === undefined) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
else {
if (containerOptions.defaultScope !== undefined &&
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
}
if (containerOptions.autoBindInjectable !== undefined &&
typeof containerOptions.autoBindInjectable !== "boolean") {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_AUTO_BIND_INJECTABLE);
}
}
else if (containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Singleton &&
containerOptions.defaultScope !== literal_types_1.BindingScopeEnum.Transient) {
throw new Error("" + ERROR_MSGS.CONTAINER_OPTIONS_INVALID_DEFAULT_SCOPE);
}
this.options = {
autoBindInjectable: containerOptions.autoBindInjectable,
defaultScope: containerOptions.defaultScope

@@ -35,2 +40,3 @@ };

this.options = {
autoBindInjectable: false,
defaultScope: literal_types_1.BindingScopeEnum.Transient

@@ -120,5 +126,4 @@ };

Container.prototype.bind = function (serviceIdentifier) {
var defaultScope = literal_types_1.BindingScopeEnum.Transient;
defaultScope = (this.options.defaultScope === defaultScope) ? defaultScope : literal_types_1.BindingScopeEnum.Singleton;
var binding = new binding_1.Binding(serviceIdentifier, defaultScope);
var scope = this.options.defaultScope || literal_types_1.BindingScopeEnum.Transient;
var binding = new binding_1.Binding(serviceIdentifier, scope);
this._bindingDictionary.add(serviceIdentifier, binding);

@@ -125,0 +130,0 @@ return new binding_to_syntax_1.BindingToSyntax(binding);

@@ -28,5 +28,12 @@ "use strict";

}
function _getActiveBindings(avoidConstraints, context, parentRequest, target) {
function _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target) {
var bindings = getBindings(context.container, target.serviceIdentifier);
var activeBindings = [];
if (bindings.length === binding_count_1.BindingCount.NoBindingsAvailable &&
context.container.options.autoBindInjectable &&
typeof target.serviceIdentifier === "function" &&
metadataReader.getConstructorMetadata(target.serviceIdentifier).compilerGeneratedMetadata) {
context.container.bind(target.serviceIdentifier).toSelf();
bindings = getBindings(context.container, target.serviceIdentifier);
}
if (avoidConstraints === false) {

@@ -78,3 +85,3 @@ activeBindings = bindings.filter(function (binding) {

if (parentRequest === null) {
activeBindings = _getActiveBindings(avoidConstraints, context, null, target);
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, null, target);
childRequest_1 = new request_1.Request(serviceIdentifier, context, null, activeBindings, target);

@@ -85,3 +92,3 @@ var thePlan = new plan_1.Plan(context, childRequest_1);

else {
activeBindings = _getActiveBindings(avoidConstraints, context, parentRequest, target);
activeBindings = _getActiveBindings(metadataReader, avoidConstraints, context, parentRequest, target);
childRequest_1 = parentRequest.addChildRequest(target.serviceIdentifier, activeBindings, target);

@@ -95,2 +102,5 @@ }

else {
if (binding.cache) {
return;
}
subChildRequest = childRequest_1;

@@ -97,0 +107,0 @@ }

{
"name": "inversify",
"version": "4.3.0",
"version": "4.4.0",
"description": "A powerful and lightweight inversion of control container for JavaScript and Node.js apps powered by TypeScript.",

@@ -38,44 +38,44 @@ "main": "lib/inversify.js",

"devDependencies": {
"@types/chai": "^4.0.1",
"@types/harmony-proxy": "^1.0.27",
"@types/mocha": "^ 2.2.35",
"@types/sinon": "^2.1.0",
"bluebird": "^3.5.0",
"browserify": "^14.0.0",
"chai": "^4.0.2",
"del": "^3.0.0",
"es6-symbol": "^3.1.0",
"gulp": "^3.9.0",
"gulp-istanbul": "^1.0.0",
"@types/chai": "4.0.4",
"@types/harmony-proxy": "1.0.29",
"@types/mocha": " 2.2.44",
"@types/sinon": "2.3.7",
"bluebird": "3.5.1",
"browserify": "14.5.0",
"chai": "4.1.2",
"del": "3.0.0",
"es6-symbol": "3.1.1",
"gulp": "3.9.1",
"gulp-istanbul": "1.1.2",
"gulp-mocha": "3.0.1",
"gulp-rename": "^1.2.2",
"gulp-sourcemaps": "^2.2.1",
"gulp-tslint": "^8.0.0",
"gulp-typescript": "^3.0.0",
"gulp-uglify": "^3.0.0",
"harmonize": "^2.0.0",
"harmony-proxy": "^1.0.0",
"istanbul": "^0.4.2",
"karma": "^1.1.2",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-commonjs": "^1.0.0",
"karma-es6-shim": "^1.0.0",
"karma-firefox-launcher": "^1.0.0",
"karma-ie-launcher": "^1.0.0",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.0.5",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sinon": "^1.0.5",
"mocha": "^3.0.1",
"performance-now": "^2.0.0",
"publish-please": "^2.1.4",
"reflect-metadata": "^0.1.9",
"run-sequence": "^2.0.0",
"sinon": "^2.0.0",
"tslint": "^5.0.0",
"typescript": "^2.4.1",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
"gulp-rename": "1.2.2",
"gulp-sourcemaps": "2.6.1",
"gulp-tslint": "8.1.2",
"gulp-typescript": "3.2.3",
"gulp-uglify": "3.0.0",
"harmonize": "2.0.0",
"harmony-proxy": "1.0.1",
"istanbul": "0.4.5",
"karma": "1.7.1",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "2.2.0",
"karma-commonjs": "1.0.0",
"karma-es6-shim": "1.0.0",
"karma-firefox-launcher": "1.0.1",
"karma-ie-launcher": "1.0.0",
"karma-mocha": "1.3.0",
"karma-mocha-reporter": "2.2.5",
"karma-phantomjs-launcher": "1.0.4",
"karma-sinon": "1.0.5",
"mocha": "4.0.1",
"performance-now": "2.1.0",
"publish-please": "2.3.1",
"reflect-metadata": "0.1.10",
"run-sequence": "2.2.0",
"sinon": "4.0.2",
"tslint": "5.8.0",
"typescript": "2.5.3",
"vinyl-buffer": "1.0.0",
"vinyl-source-stream": "1.1.0"
}
}

@@ -23,4 +23,4 @@ # InversifyJS

InversifyJS is a lightweight (4KB) inversion of control (IoC) container for TypeScript and JavaScript apps.
A IoC container uses a class constructor to identify and inject its dependencies.
InversifyJS has a friendly API and encourage the usage of the best OOP and IoC practices.
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.

@@ -107,2 +107,4 @@ ## Motivation

```ts
// file interfaces.ts
interface Warrior {

@@ -125,3 +127,5 @@ fight(): string;

```ts
let TYPES = {
// file types.ts
const TYPES = {
Warrior: Symbol("Warrior"),

@@ -144,4 +148,7 @@ Weapon: Symbol("Weapon"),

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

@@ -201,7 +208,10 @@

```ts
// file inversify.config.ts
import { Container } from "inversify";
import TYPES from "./types";
import { Warrior, Weapon, ThrowableWeapon } from "./interfaces";
import { Ninja, Katana, Shuriken } from "./entities";
var myContainer = new Container();
const myContainer = new Container();
myContainer.bind<Warrior>(TYPES.Warrior).to(Ninja);

@@ -222,3 +232,3 @@ myContainer.bind<Weapon>(TYPES.Weapon).to(Katana);

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

@@ -225,0 +235,0 @@ expect(ninja.fight()).eql("cut!"); // true

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc