@noego/ioc 0.0.7 → 0.0.8

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.
Files changed (181) hide show
  1. package/dist/framework/decorators/Component.cjs +41 -0
  2. package/dist/framework/decorators/Component.cjs.map +1 -0
  3. package/dist/framework/decorators/Component.d.cts +12 -0
  4. package/dist/framework/decorators/Component.d.ts +12 -0
  5. package/dist/framework/decorators/Component.js +17 -0
  6. package/dist/framework/decorators/Component.js.map +1 -0
  7. package/dist/framework/decorators/Inject.cjs +37 -0
  8. package/dist/framework/decorators/Inject.cjs.map +1 -0
  9. package/dist/{cjs/framework/decorators/Inject.d.ts → framework/decorators/Inject.d.cts} +3 -2
  10. package/dist/{esm/framework → framework}/decorators/Inject.d.ts +3 -2
  11. package/dist/framework/decorators/Inject.js +13 -0
  12. package/dist/framework/decorators/Inject.js.map +1 -0
  13. package/dist/framework/decorators/index.cjs +35 -0
  14. package/dist/framework/decorators/index.cjs.map +1 -0
  15. package/dist/framework/decorators/index.d.cts +4 -0
  16. package/dist/framework/decorators/index.d.ts +4 -0
  17. package/dist/framework/decorators/index.js +8 -0
  18. package/dist/framework/decorators/index.js.map +1 -0
  19. package/dist/framework/decorators/metadataKeys.cjs +35 -0
  20. package/dist/framework/decorators/metadataKeys.cjs.map +1 -0
  21. package/dist/framework/decorators/metadataKeys.d.cts +5 -0
  22. package/dist/framework/decorators/metadataKeys.d.ts +5 -0
  23. package/dist/framework/decorators/metadataKeys.js +9 -0
  24. package/dist/framework/decorators/metadataKeys.js.map +1 -0
  25. package/dist/framework/errors/ContainerErrors.cjs +61 -0
  26. package/dist/framework/errors/ContainerErrors.cjs.map +1 -0
  27. package/dist/{cjs/framework/errors/ContainerErrors.d.ts → framework/errors/ContainerErrors.d.cts} +7 -5
  28. package/dist/{esm/framework → framework}/errors/ContainerErrors.d.ts +7 -5
  29. package/dist/framework/errors/ContainerErrors.js +33 -0
  30. package/dist/framework/errors/ContainerErrors.js.map +1 -0
  31. package/dist/framework/implementation/Container.cjs +342 -0
  32. package/dist/framework/implementation/Container.cjs.map +1 -0
  33. package/dist/{cjs/framework/implementation/Container.d.ts → framework/implementation/Container.d.cts} +9 -6
  34. package/dist/{esm/framework → framework}/implementation/Container.d.ts +9 -6
  35. package/dist/framework/implementation/Container.js +320 -0
  36. package/dist/framework/implementation/Container.js.map +1 -0
  37. package/dist/framework/implementation/DecoratorSupport.cjs +92 -0
  38. package/dist/framework/implementation/DecoratorSupport.cjs.map +1 -0
  39. package/dist/framework/implementation/DecoratorSupport.d.cts +33 -0
  40. package/dist/framework/implementation/DecoratorSupport.d.ts +33 -0
  41. package/dist/framework/implementation/DecoratorSupport.js +63 -0
  42. package/dist/framework/implementation/DecoratorSupport.js.map +1 -0
  43. package/dist/framework/implementation/LoadAs.cjs +34 -0
  44. package/dist/framework/implementation/LoadAs.cjs.map +1 -0
  45. package/dist/{esm/framework/implementation/LoadAs.d.ts → framework/implementation/LoadAs.d.cts} +3 -1
  46. package/dist/{cjs/framework → framework}/implementation/LoadAs.d.ts +3 -1
  47. package/dist/framework/implementation/LoadAs.js +10 -0
  48. package/dist/framework/implementation/LoadAs.js.map +1 -0
  49. package/dist/framework/implementation/Parameter.cjs +82 -0
  50. package/dist/framework/implementation/Parameter.cjs.map +1 -0
  51. package/dist/{esm/framework/implementation/Parameter.d.ts → framework/implementation/Parameter.d.cts} +4 -2
  52. package/dist/{cjs/framework → framework}/implementation/Parameter.d.ts +4 -2
  53. package/dist/framework/implementation/Parameter.js +47 -0
  54. package/dist/framework/implementation/Parameter.js.map +1 -0
  55. package/dist/framework/interface/Container.cjs +17 -0
  56. package/dist/framework/interface/Container.cjs.map +1 -0
  57. package/dist/{esm/framework/interface/Container.d.ts → framework/interface/Container.d.cts} +10 -7
  58. package/dist/{cjs/framework → framework}/interface/Container.d.ts +10 -7
  59. package/dist/framework/interface/Container.js +1 -0
  60. package/dist/framework/interface/Container.js.map +1 -0
  61. package/dist/index.cjs +58 -0
  62. package/dist/index.cjs.map +1 -0
  63. package/dist/index.d.cts +12 -0
  64. package/dist/index.d.ts +12 -0
  65. package/dist/index.js +24 -0
  66. package/dist/index.js.map +1 -0
  67. package/package.json +16 -14
  68. package/dist/cjs/framework/decorators/Component.d.ts +0 -10
  69. package/dist/cjs/framework/decorators/Component.js +0 -25
  70. package/dist/cjs/framework/decorators/Component.js.map +0 -1
  71. package/dist/cjs/framework/decorators/Inject.js +0 -22
  72. package/dist/cjs/framework/decorators/Inject.js.map +0 -1
  73. package/dist/cjs/framework/decorators/index.d.ts +0 -3
  74. package/dist/cjs/framework/decorators/index.js +0 -24
  75. package/dist/cjs/framework/decorators/index.js.map +0 -1
  76. package/dist/cjs/framework/decorators/metadataKeys.d.ts +0 -3
  77. package/dist/cjs/framework/decorators/metadataKeys.js +0 -8
  78. package/dist/cjs/framework/decorators/metadataKeys.js.map +0 -1
  79. package/dist/cjs/framework/errors/ContainerErrors.js +0 -52
  80. package/dist/cjs/framework/errors/ContainerErrors.js.map +0 -1
  81. package/dist/cjs/framework/implementation/Container.js +0 -448
  82. package/dist/cjs/framework/implementation/Container.js.map +0 -1
  83. package/dist/cjs/framework/implementation/Container.test.d.ts +0 -1
  84. package/dist/cjs/framework/implementation/Container.test.js +0 -184
  85. package/dist/cjs/framework/implementation/Container.test.js.map +0 -1
  86. package/dist/cjs/framework/implementation/ContainerAsync.test.d.ts +0 -1
  87. package/dist/cjs/framework/implementation/ContainerAsync.test.js +0 -178
  88. package/dist/cjs/framework/implementation/ContainerAsync.test.js.map +0 -1
  89. package/dist/cjs/framework/implementation/ContainerBasic.test.d.ts +0 -1
  90. package/dist/cjs/framework/implementation/ContainerBasic.test.js +0 -101
  91. package/dist/cjs/framework/implementation/ContainerBasic.test.js.map +0 -1
  92. package/dist/cjs/framework/implementation/ContainerDecorators.test.d.ts +0 -1
  93. package/dist/cjs/framework/implementation/ContainerDecorators.test.js +0 -517
  94. package/dist/cjs/framework/implementation/ContainerDecorators.test.js.map +0 -1
  95. package/dist/cjs/framework/implementation/ContainerExtension.test.d.ts +0 -1
  96. package/dist/cjs/framework/implementation/ContainerExtension.test.js +0 -169
  97. package/dist/cjs/framework/implementation/ContainerExtension.test.js.map +0 -1
  98. package/dist/cjs/framework/implementation/ContainerLifetimes.test.d.ts +0 -1
  99. package/dist/cjs/framework/implementation/ContainerLifetimes.test.js +0 -154
  100. package/dist/cjs/framework/implementation/ContainerLifetimes.test.js.map +0 -1
  101. package/dist/cjs/framework/implementation/DecoratorSupport.d.ts +0 -31
  102. package/dist/cjs/framework/implementation/DecoratorSupport.js +0 -96
  103. package/dist/cjs/framework/implementation/DecoratorSupport.js.map +0 -1
  104. package/dist/cjs/framework/implementation/LoadAs.js +0 -10
  105. package/dist/cjs/framework/implementation/LoadAs.js.map +0 -1
  106. package/dist/cjs/framework/implementation/Parameter.js +0 -87
  107. package/dist/cjs/framework/implementation/Parameter.js.map +0 -1
  108. package/dist/cjs/framework/implementation/Parameter.test.d.ts +0 -1
  109. package/dist/cjs/framework/implementation/Parameter.test.js +0 -19
  110. package/dist/cjs/framework/implementation/Parameter.test.js.map +0 -1
  111. package/dist/cjs/framework/implementation/SimpleDecoratorTest.test.d.ts +0 -1
  112. package/dist/cjs/framework/implementation/SimpleDecoratorTest.test.js +0 -78
  113. package/dist/cjs/framework/implementation/SimpleDecoratorTest.test.js.map +0 -1
  114. package/dist/cjs/framework/implementation/SingletonTest.test.d.ts +0 -1
  115. package/dist/cjs/framework/implementation/SingletonTest.test.js +0 -85
  116. package/dist/cjs/framework/implementation/SingletonTest.test.js.map +0 -1
  117. package/dist/cjs/framework/interface/Container.js +0 -3
  118. package/dist/cjs/framework/interface/Container.js.map +0 -1
  119. package/dist/cjs/index.d.ts +0 -18
  120. package/dist/cjs/index.js +0 -24
  121. package/dist/cjs/index.js.map +0 -1
  122. package/dist/cjs/jest.config.d.ts +0 -3
  123. package/dist/cjs/jest.config.js +0 -9
  124. package/dist/cjs/jest.config.js.map +0 -1
  125. package/dist/esm/framework/decorators/Component.d.ts +0 -10
  126. package/dist/esm/framework/decorators/Component.js +0 -21
  127. package/dist/esm/framework/decorators/Component.js.map +0 -1
  128. package/dist/esm/framework/decorators/Inject.js +0 -19
  129. package/dist/esm/framework/decorators/Inject.js.map +0 -1
  130. package/dist/esm/framework/decorators/index.d.ts +0 -3
  131. package/dist/esm/framework/decorators/index.js +0 -5
  132. package/dist/esm/framework/decorators/index.js.map +0 -1
  133. package/dist/esm/framework/decorators/metadataKeys.d.ts +0 -3
  134. package/dist/esm/framework/decorators/metadataKeys.js +0 -5
  135. package/dist/esm/framework/decorators/metadataKeys.js.map +0 -1
  136. package/dist/esm/framework/errors/ContainerErrors.js +0 -44
  137. package/dist/esm/framework/errors/ContainerErrors.js.map +0 -1
  138. package/dist/esm/framework/implementation/Container.js +0 -432
  139. package/dist/esm/framework/implementation/Container.js.map +0 -1
  140. package/dist/esm/framework/implementation/Container.test.d.ts +0 -1
  141. package/dist/esm/framework/implementation/Container.test.js +0 -173
  142. package/dist/esm/framework/implementation/Container.test.js.map +0 -1
  143. package/dist/esm/framework/implementation/ContainerAsync.test.d.ts +0 -1
  144. package/dist/esm/framework/implementation/ContainerAsync.test.js +0 -151
  145. package/dist/esm/framework/implementation/ContainerAsync.test.js.map +0 -1
  146. package/dist/esm/framework/implementation/ContainerBasic.test.d.ts +0 -1
  147. package/dist/esm/framework/implementation/ContainerBasic.test.js +0 -90
  148. package/dist/esm/framework/implementation/ContainerBasic.test.js.map +0 -1
  149. package/dist/esm/framework/implementation/ContainerDecorators.test.d.ts +0 -1
  150. package/dist/esm/framework/implementation/ContainerDecorators.test.js +0 -498
  151. package/dist/esm/framework/implementation/ContainerDecorators.test.js.map +0 -1
  152. package/dist/esm/framework/implementation/ContainerExtension.test.d.ts +0 -1
  153. package/dist/esm/framework/implementation/ContainerExtension.test.js +0 -158
  154. package/dist/esm/framework/implementation/ContainerExtension.test.js.map +0 -1
  155. package/dist/esm/framework/implementation/ContainerLifetimes.test.d.ts +0 -1
  156. package/dist/esm/framework/implementation/ContainerLifetimes.test.js +0 -143
  157. package/dist/esm/framework/implementation/ContainerLifetimes.test.js.map +0 -1
  158. package/dist/esm/framework/implementation/DecoratorSupport.d.ts +0 -31
  159. package/dist/esm/framework/implementation/DecoratorSupport.js +0 -87
  160. package/dist/esm/framework/implementation/DecoratorSupport.js.map +0 -1
  161. package/dist/esm/framework/implementation/LoadAs.js +0 -7
  162. package/dist/esm/framework/implementation/LoadAs.js.map +0 -1
  163. package/dist/esm/framework/implementation/Parameter.js +0 -49
  164. package/dist/esm/framework/implementation/Parameter.js.map +0 -1
  165. package/dist/esm/framework/implementation/Parameter.test.d.ts +0 -1
  166. package/dist/esm/framework/implementation/Parameter.test.js +0 -17
  167. package/dist/esm/framework/implementation/Parameter.test.js.map +0 -1
  168. package/dist/esm/framework/implementation/SimpleDecoratorTest.test.d.ts +0 -1
  169. package/dist/esm/framework/implementation/SimpleDecoratorTest.test.js +0 -67
  170. package/dist/esm/framework/implementation/SimpleDecoratorTest.test.js.map +0 -1
  171. package/dist/esm/framework/implementation/SingletonTest.test.d.ts +0 -1
  172. package/dist/esm/framework/implementation/SingletonTest.test.js +0 -74
  173. package/dist/esm/framework/implementation/SingletonTest.test.js.map +0 -1
  174. package/dist/esm/framework/interface/Container.js +0 -2
  175. package/dist/esm/framework/interface/Container.js.map +0 -1
  176. package/dist/esm/index.d.ts +0 -18
  177. package/dist/esm/index.js +0 -15
  178. package/dist/esm/index.js.map +0 -1
  179. package/dist/esm/jest.config.d.ts +0 -3
  180. package/dist/esm/jest.config.js +0 -7
  181. package/dist/esm/jest.config.js.map +0 -1
@@ -1,158 +0,0 @@
1
- import { describe } from "node:test";
2
- import { createContainer } from "./Container";
3
- import { Parameter } from "./Parameter";
4
- describe('Container Extension', () => {
5
- describe('Extended Container Inheritance', () => {
6
- it('should inherit registrations from parent container', async () => {
7
- const container = createContainer();
8
- class BaseService {
9
- }
10
- container.registerClass(BaseService);
11
- // Create an extended container
12
- const extendedContainer = container.extend();
13
- // Should be able to resolve the class from the extended container
14
- const instance = await extendedContainer.instance(BaseService);
15
- expect(instance).toBeInstanceOf(BaseService);
16
- });
17
- it('should inherit function registrations from parent container', async () => {
18
- const container = createContainer();
19
- const serviceFunc = () => ({ name: 'service' });
20
- container.registerFunction('service', serviceFunc);
21
- // Create an extended container
22
- const extendedContainer = container.extend();
23
- // Should be able to resolve the function from the extended container
24
- const instance = await extendedContainer.get('service');
25
- expect(instance).toEqual({ name: 'service' });
26
- });
27
- });
28
- describe('Override Registrations', () => {
29
- it('should allow the extended container to override class registrations from the parent', async () => {
30
- const container = createContainer();
31
- class BaseService {
32
- getName() { return 'base'; }
33
- }
34
- class OverrideService {
35
- getName() { return 'override'; }
36
- }
37
- container.registerClass(BaseService);
38
- // Create an extended container and override the registration
39
- const extendedContainer = container.extend();
40
- extendedContainer.registerClass(BaseService, { param: [] }); // Overriding with the same class
41
- // Different instances between parent and child
42
- const parentInstance = await container.instance(BaseService);
43
- const childInstance = await extendedContainer.instance(BaseService);
44
- expect(parentInstance).not.toBe(childInstance);
45
- // Now override with a completely different class
46
- extendedContainer.registerFunction(BaseService, () => new OverrideService());
47
- const overrideInstance = await extendedContainer.instance(BaseService);
48
- expect(overrideInstance).toBeInstanceOf(OverrideService);
49
- expect(overrideInstance.getName()).toBe('override');
50
- });
51
- it('should allow the extended container to override function registrations from the parent', async () => {
52
- const container = createContainer();
53
- const baseFunc = () => ({ name: 'base' });
54
- const overrideFunc = () => ({ name: 'override' });
55
- container.registerFunction('service', baseFunc);
56
- // Create an extended container and override the registration
57
- const extendedContainer = container.extend();
58
- extendedContainer.registerFunction('service', overrideFunc);
59
- // Check that the parent registration is unchanged
60
- const parentResult = await container.get('service');
61
- expect(parentResult).toEqual({ name: 'base' });
62
- // Check that the child registration is overridden
63
- const childResult = await extendedContainer.get('service');
64
- expect(childResult).toEqual({ name: 'override' });
65
- });
66
- });
67
- describe('Isolation of Changes', () => {
68
- it('should ensure that changes in the extended container do not affect the parent', async () => {
69
- const container = createContainer();
70
- class BaseService {
71
- }
72
- container.registerClass(BaseService);
73
- // Create an extended container
74
- const extendedContainer = container.extend();
75
- // Add a new registration to the extended container
76
- class ChildOnlyService {
77
- }
78
- extendedContainer.registerClass(ChildOnlyService);
79
- // Parent container should not have access to the new registration
80
- expect(async () => {
81
- await container.instance(ChildOnlyService);
82
- }).rejects.toThrow();
83
- // Child container should have access to both registrations
84
- const baseInstance = await extendedContainer.instance(BaseService);
85
- const childInstance = await extendedContainer.instance(ChildOnlyService);
86
- expect(baseInstance).toBeInstanceOf(BaseService);
87
- expect(childInstance).toBeInstanceOf(ChildOnlyService);
88
- });
89
- });
90
- describe('Parameter Handling in Extended Containers', () => {
91
- it('should pass parameters correctly in extended containers', async () => {
92
- const container = createContainer();
93
- class ConfigService {
94
- constructor(value) {
95
- this.value = value;
96
- }
97
- }
98
- const CONFIG_VALUE = Parameter.create();
99
- container.registerClass(ConfigService, { param: [CONFIG_VALUE] });
100
- // Create an extended container
101
- const extendedContainer = container.extend();
102
- // Should be able to resolve with parameters in both containers
103
- const parentInstance = await container.instance(ConfigService, [CONFIG_VALUE.value('parent')]);
104
- const childInstance = await extendedContainer.instance(ConfigService, [CONFIG_VALUE.value('child')]);
105
- expect(parentInstance.value).toBe('parent');
106
- expect(childInstance.value).toBe('child');
107
- });
108
- });
109
- describe('Multi-Level Extension', () => {
110
- it('should support multiple levels of container extension', async () => {
111
- const root = createContainer();
112
- class RootService {
113
- getLevel() { return 'root'; }
114
- }
115
- root.registerClass(RootService);
116
- // Level 1 extension
117
- const level1 = root.extend();
118
- class Level1Service {
119
- getLevel() { return 'level1'; }
120
- }
121
- level1.registerClass(Level1Service);
122
- level1.registerFunction(RootService, () => {
123
- const service = new RootService();
124
- return {
125
- getLevel: () => `level1-override-${service.getLevel()}`
126
- };
127
- });
128
- // Level 2 extension
129
- const level2 = level1.extend();
130
- class Level2Service {
131
- getLevel() { return 'level2'; }
132
- }
133
- level2.registerClass(Level2Service);
134
- // Each level has access to its own registrations and parent registrations
135
- const rootFromRoot = await root.instance(RootService);
136
- const rootFromLevel1 = await level1.instance(RootService);
137
- const rootFromLevel2 = await level2.instance(RootService);
138
- expect(rootFromRoot.getLevel()).toBe('root');
139
- expect(rootFromLevel1.getLevel()).toBe('level1-override-root');
140
- expect(rootFromLevel2.getLevel()).toBe('level1-override-root');
141
- // Lower levels can't access higher level registrations
142
- await expect(async () => {
143
- await root.instance(Level1Service);
144
- }).rejects.toThrow();
145
- await expect(async () => {
146
- await level1.instance(Level2Service);
147
- }).rejects.toThrow();
148
- // But higher levels can access their own registrations
149
- const level1FromLevel1 = await level1.instance(Level1Service);
150
- const level1FromLevel2 = await level2.instance(Level1Service);
151
- const level2FromLevel2 = await level2.instance(Level2Service);
152
- expect(level1FromLevel1.getLevel()).toBe('level1');
153
- expect(level1FromLevel2.getLevel()).toBe('level1');
154
- expect(level2FromLevel2.getLevel()).toBe('level2');
155
- });
156
- });
157
- });
158
- //# sourceMappingURL=ContainerExtension.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContainerExtension.test.js","sourceRoot":"","sources":["../../../../framework/implementation/ContainerExtension.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAErC,OAAO,EAAa,eAAe,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,QAAQ,CAAC,gCAAgC,EAAE,GAAG,EAAE;QAC5C,EAAE,CAAC,oDAAoD,EAAE,KAAK,IAAI,EAAE;YAChE,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;YAEpC,MAAM,WAAW;aAAG;YAEpB,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YAErC,+BAA+B;YAC/B,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAgB,CAAC;YA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AK,IAAI,EAAE;gBACpB,MAAM,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAErB,uDAAuD;YACvD,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC9D,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC9D,MAAM,gBAAgB,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAE9D,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnD,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YACnD,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,143 +0,0 @@
1
- import { describe } from "node:test";
2
- import { createContainer } from "./Container";
3
- import { LoadAs } from "./LoadAs";
4
- describe('Container Lifetime Scopes', () => {
5
- // Test Transient lifetime (default)
6
- describe('Transient Lifetime', () => {
7
- it('should always create new instances for transient lifetime', async () => {
8
- const container = createContainer();
9
- class TestTransient {
10
- }
11
- container.registerClass(TestTransient); // Default is Transient
12
- const instance1 = await container.instance(TestTransient);
13
- const instance2 = await container.instance(TestTransient);
14
- expect(instance1).toBeInstanceOf(TestTransient);
15
- expect(instance2).toBeInstanceOf(TestTransient);
16
- expect(instance1).not.toBe(instance2); // Different instances
17
- });
18
- });
19
- // Test Singleton lifetime
20
- describe('Singleton Lifetime', () => {
21
- it('should reuse the same instance across the container for singleton lifetime', async () => {
22
- const container = createContainer();
23
- class TestSingleton {
24
- }
25
- container.registerClass(TestSingleton, { loadAs: LoadAs.Singleton });
26
- const instance1 = await container.instance(TestSingleton);
27
- const instance2 = await container.instance(TestSingleton);
28
- expect(instance1).toBeInstanceOf(TestSingleton);
29
- expect(instance2).toBeInstanceOf(TestSingleton);
30
- expect(instance1).toBe(instance2); // Same instance
31
- });
32
- it('should reuse the same singleton instance across extended containers', async () => {
33
- const container = createContainer();
34
- class TestSingleton {
35
- }
36
- container.registerClass(TestSingleton, { loadAs: LoadAs.Singleton });
37
- const instance1 = await container.instance(TestSingleton);
38
- // Create an extended container
39
- const extendedContainer = container.extend();
40
- const instance2 = await extendedContainer.instance(TestSingleton);
41
- expect(instance1).toBe(instance2); // Same instance even in extended container
42
- });
43
- });
44
- // Test Scoped lifetime
45
- describe('Scoped Lifetime', () => {
46
- it('should reuse the same instance within a container for scoped lifetime', async () => {
47
- const container = createContainer();
48
- class TestScoped {
49
- }
50
- container.registerClass(TestScoped, { loadAs: LoadAs.Scoped });
51
- const instance1 = await container.instance(TestScoped);
52
- const instance2 = await container.instance(TestScoped);
53
- expect(instance1).toBeInstanceOf(TestScoped);
54
- expect(instance2).toBeInstanceOf(TestScoped);
55
- expect(instance1).toBe(instance2); // Same instance within the same container
56
- });
57
- it('should create new instances for scoped lifetime in extended containers', async () => {
58
- const container = createContainer();
59
- class TestScoped {
60
- }
61
- container.registerClass(TestScoped, { loadAs: LoadAs.Scoped });
62
- const instance1 = await container.instance(TestScoped);
63
- // Create an extended container
64
- const extendedContainer = container.extend();
65
- const instance2 = await extendedContainer.instance(TestScoped);
66
- expect(instance1).not.toBe(instance2); // Different instances in different containers
67
- });
68
- });
69
- // Test different lifetime combinations with nested dependencies
70
- describe('Mixed Lifetime Dependencies', () => {
71
- it('should handle a transient class with a singleton dependency', async () => {
72
- const container = createContainer();
73
- class SingletonDep {
74
- }
75
- class TransientWithSingletonDep {
76
- constructor(dep) {
77
- this.dep = dep;
78
- }
79
- }
80
- container.registerClass(SingletonDep, { loadAs: LoadAs.Singleton });
81
- container.registerClass(TransientWithSingletonDep, { param: [SingletonDep] });
82
- const instance1 = await container.instance(TransientWithSingletonDep);
83
- const instance2 = await container.instance(TransientWithSingletonDep);
84
- expect(instance1).not.toBe(instance2); // Different transient parent instances
85
- expect(instance1.dep).toBe(instance2.dep); // Same singleton dependency
86
- });
87
- it('should handle a singleton class with a transient dependency', async () => {
88
- const container = createContainer();
89
- class TransientDep {
90
- }
91
- class SingletonWithTransientDep {
92
- constructor(dep) {
93
- this.dep = dep;
94
- }
95
- }
96
- container.registerClass(TransientDep);
97
- container.registerClass(SingletonWithTransientDep, {
98
- param: [TransientDep],
99
- loadAs: LoadAs.Singleton
100
- });
101
- const instance1 = await container.instance(SingletonWithTransientDep);
102
- const instance2 = await container.instance(SingletonWithTransientDep);
103
- expect(instance1).toBe(instance2); // Same singleton parent instance
104
- // The transient dependency is instantiated only once when the singleton is created
105
- expect(instance1.dep).toBe(instance2.dep);
106
- });
107
- it('should handle multi-level dependencies with different lifetimes', async () => {
108
- const container = createContainer();
109
- class SingletonLeaf {
110
- }
111
- class ScopedMiddle {
112
- constructor(leaf) {
113
- this.leaf = leaf;
114
- }
115
- }
116
- class TransientRoot {
117
- constructor(middle) {
118
- this.middle = middle;
119
- }
120
- }
121
- container.registerClass(SingletonLeaf, { loadAs: LoadAs.Singleton });
122
- container.registerClass(ScopedMiddle, {
123
- param: [SingletonLeaf],
124
- loadAs: LoadAs.Scoped
125
- });
126
- container.registerClass(TransientRoot, {
127
- param: [ScopedMiddle]
128
- });
129
- const instance1 = await container.instance(TransientRoot);
130
- const instance2 = await container.instance(TransientRoot);
131
- expect(instance1).not.toBe(instance2); // Different transient root instances
132
- expect(instance1.middle).toBe(instance2.middle); // Same scoped middle instance
133
- expect(instance1.middle.leaf).toBe(instance2.middle.leaf); // Same singleton leaf instance
134
- // Create an extended container
135
- const extendedContainer = container.extend();
136
- const instance3 = await extendedContainer.instance(TransientRoot);
137
- expect(instance1).not.toBe(instance3); // Different transient root instances
138
- expect(instance1.middle).not.toBe(instance3.middle); // Different scoped middle instances
139
- expect(instance1.middle.leaf).toBe(instance3.middle.leaf); // Same singleton leaf instance
140
- });
141
- });
142
- });
143
- //# sourceMappingURL=ContainerLifetimes.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ContainerLifetimes.test.js","sourceRoot":"","sources":["../../../../framework/implementation/ContainerLifetimes.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,QAAQ,CAAC,2BAA2B,EAAE,GAAG,EAAE;IACvC,oCAAoC;IACpC,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;YACvE,MAAM,SAAS,GAAG,eAAe,EAAE,CAAC;YAEpC,MAAM,aAAa;aAAG;YAEtB,SAAS,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,uBAAuB;YAE/D,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAC1D,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAE1D,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;YAChD,MAAM,CAAC,SAAS,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;YAChD,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,sBAAsB;QACjE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,2BAA2B;IAC3B,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;QAChC,EAAE,CAAC,4EAA4E,EAAE,KAAK,IAAI,EAAE;YACxF,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CAAC,8BAA8B;YAC/E,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,+BAA+B;YAE1F,+BAA+B;YAC/B,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;YAElE,MAAM,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,qCAAqC;YAC5E,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,oCAAoC;YACzF,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,+BAA+B;QAC9F,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1,31 +0,0 @@
1
- import 'reflect-metadata';
2
- import { ComponentOptions } from '../decorators/Component';
3
- import { LoadAs } from './LoadAs';
4
- /**
5
- * Gets component options from a class decorated with @Component.
6
- * Checks both Symbol and string keys for compatibility/debugging.
7
- */
8
- export declare function getComponentOptions(target: any): ComponentOptions | null;
9
- /**
10
- * Gets the scope from a class decorated with @Component.
11
- */
12
- export declare function getScope(target: any): LoadAs;
13
- /**
14
- * Gets the parameter types for a class constructor using TypeScript metadata.
15
- */
16
- export declare function getParameterTypes(target: any): any[];
17
- /**
18
- * Gets the explicitly injected tokens for a class constructor using @Inject.
19
- */
20
- export declare function getInjectTokens(target: any): Map<number, any>;
21
- /**
22
- * Gets the final list of dependencies to resolve for a constructor,
23
- * prioritizing @Inject tokens over reflected types.
24
- */
25
- export declare function getResolvedDependencies(target: any): any[];
26
- export interface ClassMetadata {
27
- hasComponent: boolean;
28
- scope: LoadAs;
29
- dependencies: any[];
30
- }
31
- export declare function getClassMetadata(target: any): ClassMetadata;
@@ -1,87 +0,0 @@
1
- // framework/implementation/DecoratorSupport.ts
2
- import 'reflect-metadata';
3
- import { COMPONENT_OPTIONS_METADATA_KEY, INJECT_TOKEN_METADATA_KEY, PARAM_TYPES_METADATA_KEY } from '../decorators/metadataKeys';
4
- import { LoadAs } from './LoadAs';
5
- /**
6
- * Gets component options from a class decorated with @Component.
7
- * Checks both Symbol and string keys for compatibility/debugging.
8
- */
9
- export function getComponentOptions(target) {
10
- if (!target || typeof target !== 'function')
11
- return null;
12
- // Prioritize the Symbol key
13
- let options = Reflect.getMetadata(COMPONENT_OPTIONS_METADATA_KEY, target);
14
- // Fallback to the string key if Symbol key didn't return anything
15
- if (options === undefined || options === null) { // Check explicitly for undefined/null
16
- options = Reflect.getMetadata('ComponentOptions', target);
17
- }
18
- // console.log(`[DecoratorSupport getComponentOptions] for ${target.name}:`, options);
19
- return options || null; // Return null if no options found with either key
20
- }
21
- /**
22
- * Gets the scope from a class decorated with @Component.
23
- */
24
- export function getScope(target) {
25
- const options = getComponentOptions(target);
26
- // Default to Transient if no options or no scope specified
27
- const scope = options?.scope ?? LoadAs.Transient;
28
- // console.log(`[DecoratorSupport getScope] for ${target.name}:`, scope);
29
- return scope;
30
- }
31
- /**
32
- * Gets the parameter types for a class constructor using TypeScript metadata.
33
- */
34
- export function getParameterTypes(target) {
35
- if (!target || typeof target !== 'function')
36
- return [];
37
- const types = Reflect.getMetadata(PARAM_TYPES_METADATA_KEY, target) || [];
38
- // console.log(`[DecoratorSupport getParameterTypes] for ${target.name}:`, types);
39
- return types;
40
- }
41
- /**
42
- * Gets the explicitly injected tokens for a class constructor using @Inject.
43
- */
44
- export function getInjectTokens(target) {
45
- if (!target || typeof target !== 'function')
46
- return new Map();
47
- const tokens = Reflect.getOwnMetadata(INJECT_TOKEN_METADATA_KEY, target) || new Map();
48
- // console.log(`[DecoratorSupport getInjectTokens] for ${target.name}:`, tokens);
49
- return tokens;
50
- }
51
- /**
52
- * Gets the final list of dependencies to resolve for a constructor,
53
- * prioritizing @Inject tokens over reflected types.
54
- */
55
- export function getResolvedDependencies(target) {
56
- if (!target || typeof target !== 'function')
57
- return [];
58
- const paramTypes = getParameterTypes(target);
59
- const injectTokens = getInjectTokens(target);
60
- const size = Math.max(paramTypes.length, injectTokens.size);
61
- Array.from({ length: size });
62
- const dependencies = Array.from({ length: size }).map((_, index) => {
63
- // If an @Inject token exists for this parameter index, use it.
64
- if (injectTokens.has(index)) {
65
- return injectTokens.get(index);
66
- }
67
- let type = paramTypes.length > index ? paramTypes[index] : undefined;
68
- // Otherwise, use the reflected type.
69
- // Handle potential 'undefined' types from reflection if interfaces are used without @Inject
70
- if (type === undefined) {
71
- console.warn(`[IOC DecoratorSupport] Reflected parameter type at index ${index} for ${target.name} is undefined. This might indicate an interface used without @Inject.`);
72
- // Depending on strictness, could throw or return a special marker. Returning undefined for now.
73
- }
74
- return type;
75
- });
76
- // console.log(`[DecoratorSupport getResolvedDependencies] for ${target.name}:`, dependencies);
77
- return dependencies;
78
- }
79
- export function getClassMetadata(target) {
80
- const options = getComponentOptions(target);
81
- return {
82
- hasComponent: !!options,
83
- scope: getScope(target), // Uses getComponentOptions internally
84
- dependencies: getResolvedDependencies(target) // Uses helpers internally
85
- };
86
- }
87
- //# sourceMappingURL=DecoratorSupport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DecoratorSupport.js","sourceRoot":"","sources":["../../../../framework/implementation/DecoratorSupport.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,kBAAkB,CAAC;AAE1B,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACjI,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAW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5C,OAAO;QACH,YAAY,EAAE,CAAC,CAAC,OAAO;QACvB,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,sCAAsC;QAC/D,YAAY,EAAE,uBAAuB,CAAC,MAAM,CAAC,CAAC,0BAA0B;KAC3E,CAAC;AACN,CAAC"}
@@ -1,7 +0,0 @@
1
- export var LoadAs;
2
- (function (LoadAs) {
3
- LoadAs[LoadAs["Singleton"] = 0] = "Singleton";
4
- LoadAs[LoadAs["Scoped"] = 1] = "Scoped";
5
- LoadAs[LoadAs["Transient"] = 2] = "Transient";
6
- })(LoadAs || (LoadAs = {}));
7
- //# sourceMappingURL=LoadAs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LoadAs.js","sourceRoot":"","sources":["../../../../framework/implementation/LoadAs.ts"],"names":[],"mappings":"AAKA,MAAM,CAAN,IAAY,MAIX;AAJD,WAAY,MAAM;IACd,6CAAS,CAAA;IACT,uCAAM,CAAA;IACN,6CAAS,CAAA;AACb,CAAC,EAJW,MAAM,KAAN,MAAM,QAIjB"}
@@ -1,49 +0,0 @@
1
- import * as randomstring from 'randomstring';
2
- /**
3
- * Parameter class for dependency injection
4
- */
5
- export class Parameter {
6
- constructor(id) {
7
- this.id = id;
8
- }
9
- /**
10
- * Create a new Parameter instance
11
- * @param name Optional name for the parameter for better error messages
12
- */
13
- static create(name) {
14
- const id = randomstring.generate(32);
15
- const param = new Parameter(id);
16
- if (name) {
17
- param.name = name;
18
- }
19
- return param;
20
- }
21
- /**
22
- * Create a ParameterValue with the specified value
23
- */
24
- value(value) {
25
- return new ParameterValue(this, value);
26
- }
27
- /**
28
- * String representation for debugging and error messages
29
- */
30
- toString() {
31
- return this.name || `Parameter_${this.id.substring(0, 8)}`;
32
- }
33
- }
34
- /**
35
- * Holds a value for a specific Parameter
36
- */
37
- export class ParameterValue {
38
- constructor(param, value) {
39
- this.param = param;
40
- this.value = value;
41
- }
42
- /**
43
- * Check if this value belongs to the given parameter
44
- */
45
- belongsTo(param) {
46
- return this.param === param;
47
- }
48
- }
49
- //# sourceMappingURL=Parameter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Parameter.js","sourceRoot":"","sources":["../../../../framework/implementation/Parameter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,cAAc,CAAC;AAE7C;;GAEG;AACH,MAAM,OAAO,SAAS;IAGlB,YAA4B,EAAU;QAAV,OAAE,GAAF,EAAE,CAAQ;IACtC,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,IAAa;QACvB,MAAM,EAAE,GAAG,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,SAAS,CAAC,EAAE,CAAC,CAAC;QAChC,IAAI,IAAI,EAAE,CAAC;YACP,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QACtB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,KAAK,CAAI,KAAQ;QACb,OAAO,IAAI,cAAc,CAAI,IAAI,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,QAAQ;QACJ,OAAO,IAAI,CAAC,IAAI,IAAI,aAAa,IAAI,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IAC/D,CAAC;CACJ;AAED;;GAEG;AACH,MAAM,OAAO,cAAc;IACvB,YAAoB,KAAgB,EAAS,KAAQ;QAAjC,UAAK,GAAL,KAAK,CAAW;QAAS,UAAK,GAAL,KAAK,CAAG;IACrD,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,KAAgB;QACtB,OAAO,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC;IAChC,CAAC;CACJ"}
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import { Parameter, ParameterValue } from './Parameter';
2
- describe('Parameter', () => {
3
- const USER_ID = Parameter.create();
4
- describe('create', () => {
5
- it('should create a new Parameter instance', () => {
6
- expect(USER_ID).toBeInstanceOf(Parameter);
7
- });
8
- });
9
- describe('value', () => {
10
- it('should create a new ParameterValue instance with the given value', () => {
11
- const user_id = USER_ID.value(1);
12
- expect(user_id).toBeInstanceOf(ParameterValue);
13
- expect(user_id.belongsTo(USER_ID)).toBe(true);
14
- });
15
- });
16
- });
17
- //# sourceMappingURL=Parameter.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Parameter.test.js","sourceRoot":"","sources":["../../../../framework/implementation/Parameter.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAIxD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACvB,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;IAEnC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACpB,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;YAC9C,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;QACnB,EAAE,CAAC,kEAAkE,EAAE,GAAG,EAAE;YACxE,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACjC,MAAM,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;YAC/C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- import 'reflect-metadata';
@@ -1,67 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- // SimpleDecoratorTest.test.ts
8
- import 'reflect-metadata';
9
- import { describe, it, expect, beforeEach } from '@jest/globals';
10
- import { createContainer } from "./Container";
11
- import { Component } from '../decorators/Component';
12
- import { LoadAs } from "./LoadAs";
13
- describe('Simple Decorator Test', () => {
14
- let container;
15
- beforeEach(() => {
16
- container = createContainer();
17
- });
18
- it('should correctly apply and read decorator metadata', () => {
19
- let TestClass = class TestClass {
20
- constructor() {
21
- this.value = Math.random();
22
- }
23
- };
24
- TestClass = __decorate([
25
- Component({ scope: LoadAs.Singleton })
26
- ], TestClass);
27
- // Check metadata is correctly set
28
- const metadata = Reflect.getMetadata('ComponentOptions', TestClass);
29
- console.log('Metadata:', metadata);
30
- expect(metadata).toBeDefined();
31
- expect(metadata.scope).toBe(LoadAs.Singleton);
32
- });
33
- it('should respect singleton scope', async () => {
34
- class TestSingleton {
35
- constructor() {
36
- this.value = Math.random();
37
- }
38
- }
39
- // Register with explicit singleton scope
40
- container.registerClass(TestSingleton, { loadAs: LoadAs.Singleton });
41
- // Get two instances
42
- const instance1 = await container.instance(TestSingleton);
43
- const instance2 = await container.instance(TestSingleton);
44
- // Should be singleton
45
- expect(instance1).toBe(instance2);
46
- expect(instance1.value).toBe(instance2.value);
47
- });
48
- it('should respect scoped lifetime', async () => {
49
- class TestScoped {
50
- constructor() {
51
- this.value = Math.random();
52
- }
53
- }
54
- // Register with explicit scoped lifetime
55
- container.registerClass(TestScoped, { loadAs: LoadAs.Scoped });
56
- // Get two instances from same container
57
- const instance1 = await container.instance(TestScoped);
58
- const instance2 = await container.instance(TestScoped);
59
- // Same container = same instance
60
- expect(instance1).toBe(instance2);
61
- // Different container = different instance
62
- const childContainer = container.extend();
63
- const instance3 = await childContainer.instance(TestScoped);
64
- expect(instance1).not.toBe(instance3);
65
- });
66
- });
67
- //# sourceMappingURL=SimpleDecoratorTest.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SimpleDecoratorTest.test.js","sourceRoot":"","sources":["../../../../framework/implementation/SimpleDecoratorTest.test.ts"],"names":[],"mappings":";;;;;;AAAA,8BAA8B;AAC9B,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACnC,IAAI,SAAqB,CAAC;IAE1B,UAAU,CAAC,GAAG,EAAE;QACZ,SAAS,GAAG,eAAe,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,oDAAoD,EAAE,GAAG,EAAE;QAE1D,IAAM,SAAS,GAAf,MAAM,SAAS;YAAf;gBACI,UAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAC1B,CAAC;SAAA,CAAA;QAFK,SAAS;YADd,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;WACjC,SAAS,CAEd;QAED,kCAAkC;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;QACpE,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACnC,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAC;QAC/B,MAAM,CAAC,QAAQ,C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