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
*`entities ([Object.<String, *>])` - the entities to register _(optional)_
126
+
-`files ([Object.<String, *>])` - the file entities to register _(optional)_
127
+
- `basePath (String)` - the absolute base path to use
128
+
- `paths (String | Array.<String> | Object.<String, String>)` - the file paths to parse, relative to the given `basePath`
129
+
- `prefix ([String=""])` - the prefix to use e.g. "app" -> "app\_myentity", etc. _(optional)_
130
+
131
+
*`dependencies ([Object.<String, *>])` - the dependencies to register for the default container (optional)
132
+
-`core ([Object.<String, *> | *])` - if present (typically with the value of `true`), registers the Node.js core modules e.g. fs, path, http, etc. as dependencies _(optional)_
133
+
- `prefix ([String=""])` - the optional prefix to use e.g. "core" -> "core\_fs", etc. _(optional)_
134
+
-`npm ([Object.<String, *> | *])` - if present (typically with the value of `true`), registers the installed NPM modules (behaves like [module.require](http://nodejs.org/api/modules.html#modules_all_together)) as dependencies _(optional)_
135
+
-`prefix ([String=""])` - the optional prefix to use e.g. "npm" -> "npm\_express", etc. _(optional)_
136
+
-`...` - the custom dependencies to register, dependency id as key `String`_(optional)_
137
+
*`containers ([Object.<String, Container>])` - the dependency containers to register _(optional)_
138
+
139
+
---
140
+
141
+
#### Properties
142
+
143
+
##### `Entities`
144
+
145
+
*`$ (Function)` - the entity resolver function and registry object (_alias for `Dips.resolve`_)
146
+
147
+
```js
148
+
// Useful if your IDE supports auto completion based on JSDOC (like PhpStorm)
*`addEntities(Object.<String, *> values)` - adds the given custom entities
162
+
163
+
*`resolve(String value)` - resolves the entity with the given name e.g. "lib.database.connection", etc.
164
+
165
+
---
166
+
167
+
##### `Containers`
168
+
169
+
*`getContainers()` - returns the ids of the registered dependency containers
170
+
171
+
*`setContainers(Object.<String, *> values)` - sets and overrides the given dependency containers
172
+
173
+
*`hasContainer(String id)` - checks if the dependency container with given id does exist
174
+
175
+
*`getContainer(String id)` - returns the dependency container with the given id
176
+
177
+
*`setContainer(String id, Container value)` - sets the dependency container with the given id and value
178
+
179
+
#### `Dependencies`
180
+
181
+
_The following methods are inherited from `Container`_
182
+
183
+
*`getDependencies()` - returns the ids of the registered dependencies within the `defaultContainer`
184
+
185
+
*`setDependencies(Object.<String, *> values)` - sets and overrides the given dependencies within the `defaultContainer`
186
+
187
+
*`addDependencies(Object.<String, *> values)` - addes the given dependencies within the `defaultContainer`
188
+
189
+
*`hasDependency(String id)` - checks if the dependency with the given id does exist within the `defaultContainer`
190
+
191
+
*`getDependency(String id)` - returns the dependency with the given id from the `defaultContainer`
192
+
193
+
*`setDependency(String id, * value)` - sets the dependency with the given id and value within the `defaultContainer`
194
+
195
+
*`invoke(Function|Array|Object|String|* value)` - invokes the given value with the dependencies from the `defaultContainer` and the provided additional _(non dependency)_ arguments
196
+
197
+
---
198
+
199
+
### Invoke explained
200
+
201
+
##### Invoke with `Function`
202
+
203
+
All function parameters starting with `$` will be replaced with the value of the corresponding dependency, `undefined` otherwise.
204
+
It is possible to pass additional function arguments (indicated without a leading `$`). The additional arguments must be passed in the corresponding order of the function parameters.
205
+
206
+
Consider the following function parameters: `foo, $db, bar, $fs`:
207
+
The additional arguments must be passed in the following order: `'value of foo', 'value of bar'`
208
+
209
+
###### Example
210
+
211
+
```js
212
+
// Invoke function
213
+
dips.invoke(function($db)
214
+
{
215
+
// $db is equal to dips.getDependency('db')
216
+
});
217
+
218
+
// Invoke function with additional arguments
219
+
dips.invoke(function($db, query)
220
+
{
221
+
// $db is equal to dips.getDependency('db')
222
+
// query is equal to the given argument
223
+
}, 'SELECT * FROM sometable');
224
+
```
225
+
226
+
##### Invoke with `Array`
227
+
228
+
By passing an array to `Dips.invoke()`, the array values will be iterated and all `String` values starting with `$` will be replaced with the value of the corresponding dependency, `undefined` otherwise.
229
+
230
+
###### Example
231
+
232
+
```js
233
+
// Invoke array
234
+
dips.invoke(['$fs', '$path', {}]); // $fs and $path will be replaced with the corresponding
235
+
```
236
+
237
+
##### Invoke with `Object`
238
+
239
+
If an object is passed to `Dips.invoke()`, the object will be iterated and the value of the `keys` starting with `$` will be replaced with the corresponding dependency, `undefined` otherwise.
240
+
241
+
###### Example
242
+
243
+
```js
244
+
// Invoke object
245
+
dips.invoke({
246
+
247
+
$db_config :null, // value will be equal to dips.getDependency('db_config')
248
+
$mysql :null, // value will be equal to dips.getDependency('mysql') or require('mysql')
249
+
query :'SELECT * FROM sometable'
250
+
251
+
});
252
+
```
253
+
254
+
__Passing other types (`string`, `number`, `boolean`, `null`, `undefined`) as value of `Dips.invoke` will be returned as they are, without modification.__
0 commit comments