Context.getXxxService() used instead of "this"

Tags: #<Tag:0x00007f29a144ebd0>

I’m currently writing unit tests for org.openmrs.api.ProgramWorkflowService and a few questions have come up. This is one:

Why is Context.getProgramWorkflowService() used instead of this ? Like in

 public Program getProgram(String name) {
  return Context.getProgramWorkflowService().getProgramByName(name);



just return the instance of ProgramWorkflowServiceImpl already in use? (And if it is a different one why would that be necessary?)

Why not

public Program getProgram(String name) {
 return this.getProgramByName(name);


Context is used to authenticate to the database and obtain services in order to interact with the system…

Context helps you to access the api hence making the service available!!