diff --git a/src/ContainerFactory.js b/src/ContainerFactory.js index aebfe28..d283a1a 100644 --- a/src/ContainerFactory.js +++ b/src/ContainerFactory.js @@ -43,7 +43,7 @@ var buildServiceDefinitionCollection = function buildServiceDefinitionCollection value.name, value.service, new FunctionArgumentCollection(functionArgumentList), - value.singleton || undefined, + value.singleton, new CallCollection(callList) )); }); diff --git a/src/ServiceDefinition.js b/src/ServiceDefinition.js index 2e83f5e..045e040 100644 --- a/src/ServiceDefinition.js +++ b/src/ServiceDefinition.js @@ -14,7 +14,7 @@ var ServiceDefinition = function ServiceDefinition(name, serviceConstructor, fun this.name = name; this.serviceConstructor = serviceConstructor; this.functionArgumentCollection = functionArgumentCollection; - this.isSingletonService = !!isSingletonService; + this.isSingletonService = (isSingletonService !== undefined ? !!isSingletonService : true); this.callCollection = callCollection; }; diff --git a/tests/fixture/valid/ServiceE.js b/tests/fixture/valid/ServiceE.js new file mode 100644 index 0000000..5dd2aa7 --- /dev/null +++ b/tests/fixture/valid/ServiceE.js @@ -0,0 +1,11 @@ +'use strict'; + +/** + * A service with no dependency. + * + * @constructor + */ +var ServiceE = function ServiceE() { +}; + +module.exports = ServiceE; diff --git a/tests/fixture/valid/services.js b/tests/fixture/valid/services.js index ca4cf56..374165e 100644 --- a/tests/fixture/valid/services.js +++ b/tests/fixture/valid/services.js @@ -42,6 +42,10 @@ module.exports = { 51 ] } + }, + { + 'name': 'foo.serviceE', + 'service': require('./ServiceE') } ] }; diff --git a/tests/functionals/ContainerFactorySpec.js b/tests/functionals/ContainerFactorySpec.js index c139a4b..e768d37 100644 --- a/tests/functionals/ContainerFactorySpec.js +++ b/tests/functionals/ContainerFactorySpec.js @@ -42,6 +42,15 @@ describe('ContainerFactory', function () { expect(firstCall).to.not.be.equal(secondCall); }); + it('should concider a service as singleton if it have no singleton configuration', function () { + var container = ContainerFactory.create(servicesConfigurationValid.services, servicesConfigurationValid.parameters); + + var firstCall = container.getService('foo.serviceE'); + var secondCall = container.getService('foo.serviceE'); + + expect(firstCall).to.equals(secondCall); + }); + it('should throw an exception on undefined parameter', function () { var container = ContainerFactory.create(servicesConfigurationValid.services, servicesConfigurationValid.parameters);