2

Currently I am rebuilding a large angularjs controller (1000+ lines), and this controller is using a large angularjs service (1000+ lines). I want to push much of the business logic from the controller to the service, but the service is getting hard to maintain. What are some techniques used for defining boundaries and splitting large services?

In our service we have public functions that are wrappers for http calls to an api, and public functions that just do business logic. Is it a good idea to split the file based on api call/business logic. Or should I try to find another way to split the files, that keeps the api calls, and relayed business logic grouped in the same file?

  • this is a bit broad and vague, I've no idea how you manage those controllers and services - but usually its a good idea to use one controller per route to avoid such scenarios - but like i said you have to provide a lot more informations on this ... – Atural Apr 01 '19 at 15:47

1 Answers1

1

I usually split a feature business logic into three sub services and put them into separate files: feature.manager, feature.utils and feature.service

feature.service contains all the async calls(ajax, websocket etc), this service doesn't have the actual business logic, it only handle the communications between client and server.

feature.utils contains all the utility methods, for example, business data structure conversion, major methods in this service should be functional.

feature.manager contains the most part of the business logic, and it should depend on feature.utils and feature.service

MarkoCen
  • 2,189
  • 13
  • 24