Skip to content

Commit 880ee94

Browse files
committed
Allows to give a function as default configuration
1 parent 4e7724e commit 880ee94

File tree

4 files changed

+3
-18
lines changed

4 files changed

+3
-18
lines changed

Diff for: package-lock.json

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
"reflect-metadata": "^0.1.12"
2020
},
2121
"dependencies": {
22-
"debug": "^3.1.0",
23-
"lodash": "^4.17.11"
22+
"debug": "^3.1.0"
2423
},
2524
"devDependencies": {
2625
"@types/debug": "^4.1.2",
27-
"@types/lodash": "^4.14.121",
2826
"gulp": "^3.9.1",
2927
"gulp-sourcemaps": "^1.12.1",
3028
"gulp-tslint": "^8.1.2",

Diff for: src/component/registry.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import cloneDeep from "lodash/cloneDeep";
2-
31
import { interfaces as inversifyInterfaces } from "inversify";
42
import {
53
ComponentRegistry as ComponentRegistryInterface,
@@ -45,7 +43,7 @@ export class ComponentRegistry implements ComponentRegistryInterface, LookupServ
4543

4644
addFromDescriptor(descriptor: ComponentDescriptor) {
4745
let interfaces = descriptor.hasOwnProperty("interfaces") ? descriptor.interfaces : {};
48-
let defaultConfig = descriptor.hasOwnProperty("defaultConfiguration") ? cloneDeep(descriptor.defaultConfiguration) : {};
46+
let defaultConfig = descriptor.hasOwnProperty("defaultConfiguration") ? (typeof descriptor.defaultConfiguration === "function" ? descriptor.defaultConfiguration() : descriptor.defaultConfiguration) : {};
4947
this.add(new ComponentImpl(descriptor.name, interfaces, defaultConfig));
5048

5149
debug("Registering bindings for " + descriptor.name + "..");

Diff for: src/interfaces/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export interface ComponentBinder {
143143
export interface ComponentDescriptor<OptionalConfiguration = {}> {
144144
name: string;
145145
interfaces?: InterfaceDescriptor;
146-
defaultConfiguration?: OptionalConfiguration;
146+
defaultConfiguration?: OptionalConfiguration | (() => OptionalConfiguration);
147147
bindings: BindingDescriptor;
148148
}
149149

0 commit comments

Comments
 (0)