Uploaded image for project: 'Nuxeo Studio'
  1. Nuxeo Studio
  2. NXS-4069

Avoid using getXxxService and storing services as private attribute

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 62
    • Fix Version/s: 73.2
    • Component/s: Technical / Transverse

      Description

      It's better not to use xxx-service as a class attribute, because it prevents some hot-reload mechanism from Java. This pattern is used everywhere in the codebase. It's better to call the service inside a method-scope:

      Bad:

      public class MyClass {
      
          private MyService myService;
      
          protected MyService getMyService() {
              if (myService == null) {
                  myService = Framework.getService(MyService.class);
              }
           }
      
          public void myMethod() {
              getMyService().doSth( ... );
          }
      }
      

      Good:

      public class MyClass {
      
          public void myMethod() {
              MyService myService = Framework.getService(MyService.class);
              myService.doSth( ... );
          }
      }
      

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour
                1h