Skip to content

Commit 14f966e

Browse files
committed
Service are now singleton by default
1 parent bc6c6ab commit 14f966e

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

src/ContainerFactory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var buildServiceDefinitionCollection = function buildServiceDefinitionCollection
4343
value.name,
4444
value.service,
4545
new FunctionArgumentCollection(functionArgumentList),
46-
value.singleton || undefined,
46+
value.singleton,
4747
new CallCollection(callList)
4848
));
4949
});

src/ServiceDefinition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var ServiceDefinition = function ServiceDefinition(name, serviceConstructor, fun
1414
this.name = name;
1515
this.serviceConstructor = serviceConstructor;
1616
this.functionArgumentCollection = functionArgumentCollection;
17-
this.isSingletonService = !!isSingletonService;
17+
this.isSingletonService = (isSingletonService !== undefined ? !!isSingletonService : true);
1818
this.callCollection = callCollection;
1919
};
2020

tests/fixture/valid/ServiceE.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
/**
4+
* A service with no dependency.
5+
*
6+
* @constructor
7+
*/
8+
var ServiceE = function ServiceE() {
9+
};
10+
11+
module.exports = ServiceE;

tests/fixture/valid/services.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ module.exports = {
4242
51
4343
]
4444
}
45+
},
46+
{
47+
'name': 'foo.serviceE',
48+
'service': require('./ServiceE')
4549
}
4650
]
4751
};

tests/functionals/ContainerFactorySpec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ describe('ContainerFactory', function () {
4242
expect(firstCall).to.not.be.equal(secondCall);
4343
});
4444

45+
it('should concider a service as singleton if it have no singleton configuration', function () {
46+
var container = ContainerFactory.create(servicesConfigurationValid.services, servicesConfigurationValid.parameters);
47+
48+
var firstCall = container.getService('foo.serviceE');
49+
var secondCall = container.getService('foo.serviceE');
50+
51+
expect(firstCall).to.equals(secondCall);
52+
});
53+
4554
it('should throw an exception on undefined parameter', function () {
4655
var container = ContainerFactory.create(servicesConfigurationValid.services, servicesConfigurationValid.parameters);
4756

0 commit comments

Comments
 (0)