title: Initialize Angular Service (factory) when application start
body: <p>In my Angular application I adding tracing functionality, which should work as separate plugin, so if script included into HTML Angular should create service and initialize (run) it. Plugin is service because it has mandatory dependency on <code>$rootScope</code>.
  For implementation I select to use Angular factory, like (code is in <code>myservice.js</code>):</p>
  
  <pre><code>angular.module('app').factory('mysevice', ['$rootScope', '$interval', serviceFunc]);
  
  function serviceFunc($rootScope, $interval) {
  
      return {
          run: function () { ... } 
      }
  }
  </code></pre>
  
  <p>And now I have problem how to immediately initialize it. My solution is to enhance Angular app <code>run</code> function (code is in myservice.js):</p>
  
  <pre><code>window.app.run(['mysevice', function (srvc) {
          srvc.run();
      }]);
  </code></pre>
  
  <p>Where app defined in separate main app.js file like:</p>
  
  <pre><code>var app = window.app = angular.module('app', [...]);
  app.run(['$state', 'breeze', ...,
  function ($state,  breeze, ...) { ..real initialization..  }
  </code></pre>
  
  <p>The code is working fine. Both main <code>run</code> and <code>run</code> for <code>myservice</code> calls are fine.  The application together with the service are working well, but the code looks ugly, especially storing the app in the global window object and multicasting the <code>run</code> function.</p>
  
  <p>Is there a better way to do Angular service and initialize it immediately after app starts with some other Angular services dependencies.</p>