title: Angular service function being called multiple times
body: <p>I have a angular service function that is being called multiple times.
  In the <code>index.html</code> page I have the following line:</p>
  
  <pre><code>&lt;li&gt;&lt;i class="pull-right"&gt;&lt;/i&gt;&lt;br/&gt;{{appCtrl.service.getCurrentUser()}}&amp;nbsp;&lt;/li&gt;
  </code></pre>
  
  <p>In the application controller I set the variable</p>
  
  <pre><code>appCtrl.controller('AppController', function ($state, securityService, $log) {
  
          $log.info('App controller');
  
          var appCtrl = this;
          appCtrl.service = securityService;
  });
  </code></pre>
  
  <p>In my service I exposed the function</p>
  
  <pre><code>   login.factory('securityService', function ($window, $log) {
  
      var currentUser;
  
      return {
          setCurrentUser: function (user) {
              currentUser = user;
              $window.sessionStorage.setItem('User', JSON.stringify(currentUser));
          },
          getCurrentUser: function () {
              $log.info('Calling current user');
              if (!currentUser) {
                  var storedObject = $window.sessionStorage.getItem('User');
                  currentUser = JSON.parse(storedObject);
              }
              return currentUser;
          }
      }
  });
  </code></pre>
  
  <p>The following line in the <code>getCurrentUser</code> function gets called multiple times when the application starts up or page refresh is being done.</p>
  
  <pre><code>$log.info('Calling current user');
  </code></pre>
  
  <p>The controller is being called only once, I monitor it by looking at <code>$log.info('App controller');</code> </p>
  
  <p>Is it being called as part of the dirty checking process or am I doing something wrong?</p>