title: Angular 4 Custom decorator - injecting services
body: <p>I want to create an authentication decorator in my application.</p>
  <p>Usage example should be simple as</p>
  <pre><code>@RequireAuthentication()
  @HostListener('click', ['$event']) onClick(event: Event) {
    // ...
  }
  </code></pre>
  <p>As I know decorator can only be function, so in some other file I plan to have</p>
  <pre><code>export function RequireAuthentication() {
      if (!userService.isAuthenticated) {
          navigationService.goToLogin();
          return;
      }
  }
  </code></pre>
  <p>The problem for me is how to properly initialize userService and navigationService in this case, since these services contain all logic for finding if a user is authenticated and showing login screen.</p>
  <p>I already tried:</p>
  <ol>
  <li>to use a class with the constructor for service initialization, but then the nested method cannot be used as a decorator</li>
  <li>to use Injectable class to create services, I need to create an instance of this class, same problem.</li>
  <li>to use ModuleWithProviders approach to hide authentication implementation and only expose decorator, but not sure if that is the right way to do this.</li>
  </ol>
  <p>Any hints would be helpful. Could be that I miss something fundamental since I'm not an experienced angular developer or there is another way to approach this problem.</p>