-
Type: Clean up
-
Status: Resolved
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: 10.10
-
Component/s: Code Refactoring (Global)
There's lots of old code caching the result of looking up a service locally, for instance doing:
protected MyService myService; protected MyService getMyService() { if (myService == null) { myService = Framework.getService(MyService.class); } return myService; }
This is a bad pattern (it's a premature optimization, the lookup is not costly) and in future Nuxeo versions the service implementation may have to change more dynamically (for hot reload or similar reconfiguration uses).
This kind of code should be changed to a simple direct lookup. The helper method may stay if it helps minimize code changes, but the field-based caching must go.
Note that caching in some transient builders or similar objects is not a problem (and should probably be done in a constructor then).