Skip to content

Commit

Permalink
Merge pull request #11 from remojansen/master
Browse files Browse the repository at this point in the history
Updated dependencies and added AMD support
  • Loading branch information
remojansen authored Dec 6, 2016
2 parents 3bdd311 + c6f3486 commit d276453
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 65 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dist
lib
es
dts
amd

type_definitions/inversify/*.js

Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"**/temp": true,
"**/coverage": true,
"**/dist": true,
"**/amd": true,
"**/docs": true,
"type_definitions/**/*.js": true
}
Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ using the `@lazyInject` decorator:

```ts
import getDecorators from "inversify-inject-decorators";
import { Kernel, injectable, tagged, named } from "inversify";
import { Container, injectable, tagged, named } from "inversify";

let kernel = new Kernel();
let { lazyInject } = getDecorators(kernel);
let container = new Container();
let { lazyInject } = getDecorators(container);
let TYPES = { Weapon: "Weapon" };

interface Weapon {
Expand All @@ -77,7 +77,7 @@ class Warrior {
public weapon: Weapon;
}

kernel.bind<Weapon>(TYPES.Weapon).to(Sword);
container.bind<Weapon>(TYPES.Weapon).to(Sword);

let warrior = new Warrior();
console.log(warrior.weapon instanceof Sword); // true
Expand All @@ -89,10 +89,10 @@ using the `@lazyInjectNamed` decorator:

```ts
import getDecorators from "inversify-inject-decorators";
import { Kernel, injectable, named } from "inversify";
import { Container, injectable, named } from "inversify";

let kernel = new Kernel();
let { lazyInjectNamed } = getDecorators(kernel);
let container = new Container();
let { lazyInjectNamed } = getDecorators(container);
let TYPES = { Weapon: "Weapon" };

interface Weapon {
Expand Down Expand Up @@ -139,8 +139,8 @@ class Warrior {

}

kernel.bind<Weapon>(TYPES.Weapon).to(Sword).whenTargetNamed("not-throwwable");
kernel.bind<Weapon>(TYPES.Weapon).to(Shuriken).whenTargetNamed("throwwable");
container.bind<Weapon>(TYPES.Weapon).to(Sword).whenTargetNamed("not-throwwable");
container.bind<Weapon>(TYPES.Weapon).to(Shuriken).whenTargetNamed("throwwable");

let warrior = new Warrior();
console.log(warrior.primaryWeapon instanceof Sword); // true
Expand All @@ -153,10 +153,10 @@ using the `@lazyInjectTagged` decorator:

```ts
import getDecorators from "inversify-inject-decorators";
import { Kernel, injectable, tagged } from "inversify";
import { Container, injectable, tagged } from "inversify";

let kernel = new Kernel();
let { lazyInjectTagged } = getDecorators(kernel);
let container = new Container();
let { lazyInjectTagged } = getDecorators(container);
let TYPES = { Weapon: "Weapon" };

interface Weapon {
Expand Down Expand Up @@ -203,8 +203,8 @@ class Warrior {

}

kernel.bind<Weapon>(TYPES.Weapon).to(Sword).whenTargetTagged("throwwable", false);
kernel.bind<Weapon>(TYPES.Weapon).to(Shuriken).whenTargetTagged("throwwable", true);
container.bind<Weapon>(TYPES.Weapon).to(Sword).whenTargetTagged("throwwable", false);
container.bind<Weapon>(TYPES.Weapon).to(Shuriken).whenTargetTagged("throwwable", true);

let warrior = new Warrior();
console.log(warrior.primaryWeapon instanceof Sword); // true
Expand All @@ -217,10 +217,10 @@ using the `@lazyMultiInject` decorator:

```ts
import getDecorators from "inversify-inject-decorators";
import { Kernel, injectable } from "inversify";
import { Container, injectable } from "inversify";

let kernel = new Kernel();
let { lazyMultiInject } = getDecorators(kernel);
let container = new Container();
let { lazyMultiInject } = getDecorators(container);
let TYPES = { Weapon: "Weapon" };

interface Weapon {
Expand Down Expand Up @@ -262,8 +262,8 @@ class Warrior {

}

kernel.bind<Weapon>(TYPES.Weapon).to(Sword);
kernel.bind<Weapon>(TYPES.Weapon).to(Shuriken);
container.bind<Weapon>(TYPES.Weapon).to(Sword);
container.bind<Weapon>(TYPES.Weapon).to(Shuriken);

let warrior = new Warrior();
console.log(warrior.weapons[0] instanceof Sword); // true
Expand Down
28 changes: 21 additions & 7 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ gulp.task("lint", function() {
])
.pipe(tslint(config))
.pipe(tslint.report());

});

//******************************************************************************
Expand All @@ -34,7 +35,7 @@ gulp.task("build-lib", function() {
return gulp.src([
"src/**/*.ts"
])
.pipe(tsc(tsLibProject))
.pipe(tsLibProject())
.on("error", function (err) {
process.exit(1);
})
Expand All @@ -47,13 +48,26 @@ gulp.task("build-es", function() {
return gulp.src([
"src/**/*.ts"
])
.pipe(tsc(tsEsProject))
.pipe(tsEsProject())
.on("error", function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("es/"));
});

var tsAmdProject = tsc.createProject("tsconfig.json", { module : "amd", typescript: require("typescript") });

gulp.task("build-es", function() {
return gulp.src([
"src/**/*.ts"
])
.pipe(tsAmdProject())
.on("error", function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("amd/"));
});

var tsDtsProject = tsc.createProject("tsconfig.json", {
declaration: true,
noExternalResolve: false,
Expand All @@ -64,7 +78,7 @@ gulp.task("build-dts", function() {
return gulp.src([
"src/**/*.ts"
])
.pipe(tsc(tsDtsProject))
.pipe(tsDtsProject())
.on("error", function (err) {
process.exit(1);
})
Expand All @@ -81,11 +95,11 @@ gulp.task("build-src", function() {
return gulp.src([
"src/**/*.ts"
])
.pipe(tsc(tstProject))
.pipe(tstProject())
.on("error", function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("src/"));
.pipe(gulp.dest("src/"));
});

var tsTestProject = tsc.createProject("tsconfig.json", { typescript: require("typescript") });
Expand All @@ -94,11 +108,11 @@ gulp.task("build-test", function() {
return gulp.src([
"test/**/*.ts"
])
.pipe(tsc(tsTestProject))
.pipe(tsTestProject())
.on("error", function (err) {
process.exit(1);
})
.js.pipe(gulp.dest("test/"));
.pipe(gulp.dest("test/"));
});

gulp.task("mocha", function() {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inversify-inject-decorators",
"version": "2.0.0",
"version": "3.0.0-beta.1",
"description": "Lazy evaluated property injection decorators for InversifyJS",
"main": "lib/index.js",
"jsnext:main": "es/index.js",
Expand Down Expand Up @@ -40,14 +40,14 @@
"gulp": "^3.9.1",
"gulp-istanbul": "^1.0.0",
"gulp-mocha": "^3.0.0",
"gulp-tslint": "^6.1.2",
"gulp-tslint": "^7.0.1",
"gulp-typescript": "^3.0.0",
"inversify": "^2.0.0",
"inversify": "^3.0.0-rc.1",
"mocha": "^3.0.2",
"publish-please": "^2.2.0",
"reflect-metadata": "^0.1.3",
"run-sequence": "^1.2.2",
"tslint": "^3.14.0",
"typescript": "^2.0.2"
"tslint": "^4.0.1",
"typescript": "^2.1.1"
}
}
16 changes: 8 additions & 8 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function _proxyGetter(
});
}

function makePropertyInjectDecorator(kernel: interfaces.Kernel) {
function makePropertyInjectDecorator(container: interfaces.Container) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(proto: any, key: string): void {

let resolve = () => {
return kernel.get(serviceIdentifier);
return container.get(serviceIdentifier);
};

_proxyGetter(proto, key, resolve);
Expand All @@ -40,12 +40,12 @@ function makePropertyInjectDecorator(kernel: interfaces.Kernel) {
};
}

function makePropertyInjectNamedDecorator(kernel: interfaces.Kernel) {
function makePropertyInjectNamedDecorator(container: interfaces.Container) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>, named: string) {
return function(proto: any, key: string): void {

let resolve = () => {
return kernel.getNamed(serviceIdentifier, named);
return container.getNamed(serviceIdentifier, named);
};

_proxyGetter(proto, key, resolve);
Expand All @@ -54,12 +54,12 @@ function makePropertyInjectNamedDecorator(kernel: interfaces.Kernel) {
};
}

function makePropertyInjectTaggedDecorator(kernel: interfaces.Kernel) {
function makePropertyInjectTaggedDecorator(container: interfaces.Container) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>, key: string, value: any) {
return function(proto: any, propertyName: string): void {

let resolve = () => {
return kernel.getTagged(serviceIdentifier, key, value);
return container.getTagged(serviceIdentifier, key, value);
};

_proxyGetter(proto, propertyName , resolve);
Expand All @@ -68,12 +68,12 @@ function makePropertyInjectTaggedDecorator(kernel: interfaces.Kernel) {
};
}

function makePropertyMultiInjectDecorator(kernel: interfaces.Kernel) {
function makePropertyMultiInjectDecorator(container: interfaces.Container) {
return function(serviceIdentifier: interfaces.ServiceIdentifier<any>) {
return function(proto: any, key: string): void {

let resolve = () => {
return kernel.getAll(serviceIdentifier);
return container.getAll(serviceIdentifier);
};

_proxyGetter(proto, key, resolve);
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {
} from "./decorators";


function getDecorators(kernel: interfaces.Kernel) {
function getDecorators(container: interfaces.Container) {

let lazyInject = makePropertyInjectDecorator(kernel);
let lazyInjectNamed = makePropertyInjectNamedDecorator(kernel);
let lazyInjectTagged = makePropertyInjectTaggedDecorator(kernel);
let lazyMultiInject = makePropertyMultiInjectDecorator(kernel);
let lazyInject = makePropertyInjectDecorator(container);
let lazyInjectNamed = makePropertyInjectNamedDecorator(container);
let lazyInjectTagged = makePropertyInjectTaggedDecorator(container);
let lazyMultiInject = makePropertyMultiInjectDecorator(container);

return {
lazyInject ,
Expand Down
Loading

0 comments on commit d276453

Please sign in to comment.