title: How to best use global service classes in Aurelia
body: <p>I have some services which are used by many classes in my application. As an example this could be a <code>LoggerService</code> which logs messages to an internal store and prints them to the console.</p>
  
  <p>This service could look something like this:</p>
  
  <pre><code>export class LoggerService {
      let _logs = [];
  
      addLog(msg) {
          this._logs.push(msg);
          console.log(this._logs.length + ': ' + msg);
      }
  }
  </code></pre>
  
  <p>I guess the usual way in Aurelia would be to use this class with dependency injection which works just fine since it uses a singleton per default. An example usage could then look something like this:</p>
  
  <pre><code>import {autoinject, Aurelia} from 'aurelia-framework';
  import {LoggerService} from 'LoggerService';
  
  @autoinject
  export class SomeViewModel {
      let _loggerService;
  
      constructor(loggerService) {
          this._loggerService = loggerService
      }
  
      somethingChanged() {
          this._loggerService.addLog('Something changed...');
      }
  }
  </code></pre>
  
  <p>Basically this approach works just fine but it feels a little "clumsy" at a larger scale and I hope that it could be simplified:</p>
  
  <ul>
  <li>Using dependency injection requires a lot of boilerplate code in each "using class" which unnecessarily "bloats" them (import statement, a dedicated class member which needs to be assigned in the constructor etc.).</li>
  <li>I'm used to having such classes inside a dedicated namespace which lives in the window object. This allows me convenient debugging since I can call code like <code>MyNamespace.LoggerService.addLog('blahblah');</code> directly from the command line. How do I accomplish this best with Aurelia?</li>
  </ul>
  
  <p>Is there an more straight forward way which would also give me a better debug experience from the command line?</p>