You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,11 +104,19 @@ class Service {
104
104
```
105
105
106
106
### 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);
108
109
109
110
```typescript
110
111
import { LifeTime } from'container-ioc';
111
112
113
+
const container =newContainer({
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
112
120
container.register([
113
121
{
114
122
token: TService,
@@ -126,15 +134,10 @@ container.register([
126
134
serve():void {}
127
135
}
128
136
},
129
-
lifeTime: LifeTime.PerRequest }
137
+
lifeTime: LifeTime.Persistent
138
+
}
130
139
]);
131
140
```
132
-
> Or you can set default life time for all items in a container by passing an option object.
133
-
```typescript
134
-
const container =newContainer({
135
-
defaultLifeTime: LifeTime.PerRequest
136
-
});
137
-
```
138
141
139
142
### Hierarchical containers.
140
143
> 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