Skip to content

Commit 7dc17f5

Browse files
author
Umed Khudoiberdiev
committed
removed provide method, replaced by set
1 parent f8742c3 commit 7dc17f5

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
## 0.6.0
4+
5+
* removed `provide` method, use `set` method instead
6+
* deprecated `Require` decorator. Use es6 imports instead or named services
7+
* other small api changes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ Container.set(CoffeeMaker, new FakeCoffeeMaker());
310310

311311
// or
312312

313-
Container.provide([
313+
Container.set([
314314
{ id: "bean.factory", value: new FakeBeanFactory() },
315315
{ id: "sugar.factory", value: new FakeSugarFactory() },
316316
{ id: "water.factory", value: new FakeWaterFactory() }

sample/sample6-provide/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {Bus} from "./Bus";
77
import {Car} from "./Car";
88

99
// provide fake implementations
10-
Container.provide([
10+
Container.set([
1111
{ id: Bus, value: new FakeBus() },
1212
{ id: Car, value: new FakeCar() }
1313
]);

src/Container.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,16 @@ export class Container {
135135
/**
136136
* Sets a value for the given type or service name in the container.
137137
*/
138-
static set(identifierOrServiceMetadata: ServiceIdentifier|ServiceMetadata<any, any>, value?: any): Container {
138+
static set(values: { id: ServiceIdentifier, value: any }[]): Container;
139+
140+
/**
141+
* Sets a value for the given type or service name in the container.
142+
*/
143+
static set(identifierOrServiceMetadata: ServiceIdentifier|ServiceMetadata<any, any>|({ id: ServiceIdentifier, value: any }[]), value?: any): Container {
144+
if (identifierOrServiceMetadata instanceof Array) {
145+
identifierOrServiceMetadata.forEach((v: any) => this.set(v.id, v.value));
146+
return this;
147+
}
139148

140149
const newService: ServiceMetadata<any, any> = arguments.length === 1 && typeof identifierOrServiceMetadata === "object" && !(identifierOrServiceMetadata instanceof Token) ? identifierOrServiceMetadata : undefined;
141150
if (newService) {
@@ -170,13 +179,6 @@ export class Container {
170179
return this;
171180
}
172181

173-
/**
174-
* Provides a set of values to be saved in the container.
175-
*/
176-
static provide(values: { id: ServiceIdentifier, value: any }[]) {
177-
values.forEach((v: any) => this.set(v.id, v.value));
178-
}
179-
180182
/**
181183
* Removes services with a given service identifiers (tokens or types).
182184
*/

test/Container.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("Container", function() {
105105

106106
});
107107

108-
describe("provide", function() {
108+
describe("set multiple", function() {
109109

110110
it("should be able to provide a list of values", function() {
111111

@@ -118,7 +118,7 @@ describe("Container", function() {
118118
const test1Service = new TestService();
119119
const test2Service = new TestService();
120120

121-
Container.provide([
121+
Container.set([
122122
{ id: TestService, value: testService },
123123
{ id: "test1-service", value: test1Service },
124124
{ id: "test2-service", value: test2Service },
@@ -145,7 +145,7 @@ describe("Container", function() {
145145
const test1Service = new TestService();
146146
const test2Service = new TestService();
147147

148-
Container.provide([
148+
Container.set([
149149
{ id: TestService, value: testService },
150150
{ id: "test1-service", value: test1Service },
151151
{ id: "test2-service", value: test2Service },

0 commit comments

Comments
 (0)