Skip to content

Commit

Permalink
fixes typestack#5
Browse files Browse the repository at this point in the history
  • Loading branch information
Umed Khudoiberdiev committed Dec 25, 2016
1 parent 79e89a9 commit 8dea995
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "typedi",
"version": "0.4.2",
"description": "Dependency injection for Typescript",
"license": "Apache-2.0",
"version": "0.4.3",
"description": "Dependency injection for TypeScript",
"license": "MIT",
"readmeFilename": "README.md",
"private": true,
"author": {
Expand Down
16 changes: 8 additions & 8 deletions src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ export class Container {
* Sets a value for the given type or service name in the container.
*/
static set(type: Function, value: any): void;
static set(name: string, type: Function, value: any): void;
static set(nameOrType: string|Function, typeOrValue: Function|any, value?: any) {
static set(name: string, value: any): void;
static set(nameOrType: string|Function, typeOrValue: Function|any) {

if (arguments.length === 3) {
if (typeof nameOrType === "string") {
this.instances.push({
name: <string> nameOrType,
type: <Function> typeOrValue,
instance: value
name: nameOrType,
type: undefined,
instance: typeOrValue
});
} else {
this.instances.push({
Expand All @@ -121,10 +121,10 @@ export class Container {
/**
* Provides a set of values to be saved in the container.
*/
static provide(values: { name?: string, type: Function, value: any }[]) {
static provide(values: { name?: string, type?: Function, value: any }[]) {
values.forEach(v => {
if (v.name) {
this.set(v.name, v.type, v.value);
this.set(v.name, v.value);
} else {
this.set(v.type, v.value);
}
Expand Down
7 changes: 2 additions & 5 deletions test/unit/Container.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import "es6-shim";
import "reflect-metadata";
import * as chai from "chai";
import {expect} from "chai";
import * as sinon from "sinon";
import {Container} from "../../src/Container";
import {Service} from "../../src/decorators";

Expand Down Expand Up @@ -54,11 +51,11 @@ describe("Container", function() {
it("should set named service", function() {
const firstService = new TestService();
firstService.name = "first";
Container.set("first.service", TestService, firstService);
Container.set("first.service", firstService);

const secondService = new TestService();
secondService.name = "second";
Container.set("second.service", TestService, secondService);
Container.set("second.service", secondService);

Container.get<TestService>("first.service").name.should.be.equal("first");
Container.get<TestService>("second.service").name.should.be.equal("second");
Expand Down

0 comments on commit 8dea995

Please sign in to comment.