According to this question:
angular.service vs angular.factory
Services are created by angular with the new keyword, meaning a new
instance of the returned object.
For example:
app.service('helloWorldService', function() {
this.hello = function() {
return "Hello World"; };
}
);
However, with factories, they are not.
Meaning a developer can, if they choose, to create new instances (by using the keyword new
) - hence, why its called a factory I assume.
My question is:
Why is angular creating a new instance of a service to begin with?
I agree that services should singletons, which they are, but whats the point of creating a new instance of the returned function? Wouldn't it be better, for services, if Angular just returned the declared function - just as they do with factories.
Doesn't that make more sense for services?
The reason I am asking is because I am, on an abstraction layer, creating services, but I am unsure if I should really use the services API over the factories API, just because creating a new instance of the declared function seems a bit pointless and overkill =\