ts-ioc-container 55.2.0 → 55.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -0
- package/cjm/hooks/HookContext.js +4 -0
- package/esm/hooks/HookContext.js +4 -0
- package/package.json +1 -1
- package/typings/hooks/HookContext.d.ts +2 -0
package/README.md
CHANGED
|
@@ -2668,6 +2668,26 @@ describe('inject property', () => {
|
|
|
2668
2668
|
expect(viewModel.greetingService).toBe('Hello');
|
|
2669
2669
|
expect(viewModel.display()).toBe('Hello User');
|
|
2670
2670
|
});
|
|
2671
|
+
|
|
2672
|
+
it('should read the applied instance property via getProperty', () => {
|
|
2673
|
+
const onInitHookRunner = new HooksRunner('onInit');
|
|
2674
|
+
|
|
2675
|
+
let injectedValue: unknown;
|
|
2676
|
+
|
|
2677
|
+
class UserViewModel {
|
|
2678
|
+
@hook('onInit', injectProp('GreetingService'), (context) => {
|
|
2679
|
+
injectedValue = context.getProperty();
|
|
2680
|
+
})
|
|
2681
|
+
greetingService!: string;
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
const container = new Container().addRegistration(Registration.fromValue('Hello').bindToKey('GreetingService'));
|
|
2685
|
+
|
|
2686
|
+
const viewModel = container.resolve(UserViewModel);
|
|
2687
|
+
onInitHookRunner.execute(viewModel, { scope: container });
|
|
2688
|
+
|
|
2689
|
+
expect(injectedValue).toBe('Hello');
|
|
2690
|
+
});
|
|
2671
2691
|
});
|
|
2672
2692
|
|
|
2673
2693
|
```
|
package/cjm/hooks/HookContext.js
CHANGED
|
@@ -26,6 +26,10 @@ class HookContext {
|
|
|
26
26
|
// @ts-ignore
|
|
27
27
|
this.instance[this.methodName] = fn.resolve(this.scope);
|
|
28
28
|
}
|
|
29
|
+
getProperty() {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return this.instance[this.methodName];
|
|
32
|
+
}
|
|
29
33
|
setInitialArgs(...args) {
|
|
30
34
|
this.initialArgs = args;
|
|
31
35
|
return this;
|
package/esm/hooks/HookContext.js
CHANGED
|
@@ -23,6 +23,10 @@ export class HookContext {
|
|
|
23
23
|
// @ts-ignore
|
|
24
24
|
this.instance[this.methodName] = fn.resolve(this.scope);
|
|
25
25
|
}
|
|
26
|
+
getProperty() {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
return this.instance[this.methodName];
|
|
29
|
+
}
|
|
26
30
|
setInitialArgs(...args) {
|
|
27
31
|
this.initialArgs = args;
|
|
28
32
|
return this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "55.
|
|
3
|
+
"version": "55.3.0",
|
|
4
4
|
"description": "Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.",
|
|
5
5
|
"workspaces": [
|
|
6
6
|
"docs"
|
|
@@ -9,6 +9,7 @@ export interface IHookContext {
|
|
|
9
9
|
args?: unknown[];
|
|
10
10
|
}): unknown;
|
|
11
11
|
setProperty(fn: InjectionToken): void;
|
|
12
|
+
getProperty(): unknown;
|
|
12
13
|
setInitialArgs(...args: unknown[]): this;
|
|
13
14
|
}
|
|
14
15
|
export declare class HookContext implements IHookContext {
|
|
@@ -22,6 +23,7 @@ export declare class HookContext implements IHookContext {
|
|
|
22
23
|
args?: unknown[];
|
|
23
24
|
}): unknown;
|
|
24
25
|
setProperty(fn: InjectionToken): void;
|
|
26
|
+
getProperty(): unknown;
|
|
25
27
|
setInitialArgs(...args: unknown[]): this;
|
|
26
28
|
}
|
|
27
29
|
export type CreateHookContext = (Target: object, scope: IContainer, methodName?: string) => IHookContext;
|