fable 3.0.142 → 3.0.143

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fable",
3
- "version": "3.0.142",
3
+ "version": "3.0.143",
4
4
  "description": "A service dependency injection, configuration and logging library.",
5
5
  "main": "source/Fable.js",
6
6
  "scripts": {
package/source/Fable.js CHANGED
@@ -171,13 +171,27 @@ class Fable extends libFableServiceBase.CoreServiceProviderBase
171
171
  {
172
172
  this.addServiceTypeIfNotExists(pServiceType, pServiceClass);
173
173
 
174
- if (!(pServiceType in this.servicesMap))
174
+ if ((!(pServiceType in this.servicesMap)) || (!(pServiceType in this.fable)))
175
175
  {
176
176
  return this.instantiateServiceProvider(pServiceType, {}, `${pServiceType}-Default`);
177
177
  }
178
178
  else
179
179
  {
180
- return this.serviceClasses[pServiceType];
180
+ return this[pServiceType];
181
+ }
182
+ }
183
+
184
+ addAndInstantiateSingletonService(pServiceType, pOptions, pServiceClass)
185
+ {
186
+ this.addServiceTypeIfNotExists(pServiceType, pServiceClass);
187
+
188
+ if ((!(pServiceType in this.servicesMap)) || (!(pServiceType in this.fable)))
189
+ {
190
+ return this.instantiateServiceProvider(pServiceType, {}, `${pServiceType}-Default`);
191
+ }
192
+ else
193
+ {
194
+ return this[pServiceType];
181
195
  }
182
196
  }
183
197
 
@@ -166,7 +166,24 @@ suite
166
166
  Expect(tmpService).to.be.an('object');
167
167
  }
168
168
  );
169
+ test
170
+ (
171
+ 'Add and instantiate a singleton service',
172
+ function ()
173
+ {
174
+ let testFable = new libFable({});
175
+
176
+ let tmpService = testFable.addAndInstantiateSingletonService('SimpleService', {}, SimpleService);
169
177
 
178
+ Expect(testFable.SimpleService).to.be.an('object');
179
+ Expect(tmpService).to.be.an('object');
180
+
181
+ let tmpService2 = testFable.addAndInstantiateSingletonService('SimpleService', {}, SimpleService);
182
+
183
+ // A second call should not construct another one.
184
+ Expect(tmpService2.Hash).to.equal(tmpService.Hash);
185
+ }
186
+ );
170
187
  test
171
188
  (
172
189
  'Change the default service provider',