Skip to content

Commit 0ce9e50

Browse files
updated readme
1 parent 463a741 commit 0ce9e50

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

README.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,19 @@ class Service {
104104
```
105105

106106
### Life Time control.
107-
> By default, containers resolve singletons when using **useClass** and **useFactory**. You can specify life time individually for each item in a container by setting **lifeTime** attribute to **LifeTime.PerRequest**.
107+
> By default, containers resolve singletons when using **useClass** and **useFactory**.
108+
Default life time for all items in a container can be set by passing an option object to it's contructor with **defailtLifeTime** attribute. Possible values: **LifeTime.PerRequest** (resolves instances) and **LifeTime.Persistent** (resolves singletons);
108109

109110
```typescript
110111
import { LifeTime } from 'container-ioc';
111112

113+
const container = new Container({
114+
defaultLifeTime: LifeTime.PerRequest
115+
});
116+
```
117+
> You can also specify life time individually for each item in a container by specifying **lifeTime** attribute.
118+
119+
```typescript
112120
container.register([
113121
{
114122
token: TService,
@@ -126,15 +134,10 @@ container.register([
126134
serve(): void {}
127135
}
128136
},
129-
lifeTime: LifeTime.PerRequest }
137+
lifeTime: LifeTime.Persistent
138+
}
130139
]);
131140
```
132-
> Or you can set default life time for all items in a container by passing an option object.
133-
```typescript
134-
const container = new Container({
135-
defaultLifeTime: LifeTime.PerRequest
136-
});
137-
```
138141

139142
### Hierarchical containers.
140143
> If a container can't find a value within itself, it will look it up in ascendant containers. There a 3 ways to set a parent for a container.

0 commit comments

Comments
 (0)