Where to put shared non-model logic?


#1

My app can be user configured to use different “rules”. Models should use these rules to do calculations.

Something like:

rules  = Rules.create({config: {}});
rules.calculateWinner(instanceOfClassA);
rules.calculateStats(instanceOfClassB);

Where should I place the Rules class? Should it be a service?

I could move the calculateSomething() methods to the models and feed it the Rules instance as a param, but I don’t want to create huge models.


#2

Services are Singletons, So you can share these states of all your application. Try it at start.