Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service are now singleton by default #25

Merged
merged 1 commit into from
Feb 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ContainerFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var buildServiceDefinitionCollection = function buildServiceDefinitionCollection
value.name,
value.service,
new FunctionArgumentCollection(functionArgumentList),
value.singleton || undefined,
value.singleton,
new CallCollection(callList)
));
});
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceDefinition.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
11 changes: 11 additions & 0 deletions tests/fixture/valid/ServiceE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

/**
* A service with no dependency.
*
* @constructor
*/
var ServiceE = function ServiceE() {
};

module.exports = ServiceE;
4 changes: 4 additions & 0 deletions tests/fixture/valid/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ module.exports = {
51
]
}
},
{
'name': 'foo.serviceE',
'service': require('./ServiceE')
}
]
};
9 changes: 9 additions & 0 deletions tests/functionals/ContainerFactorySpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down