title: How to provide a service that uses generics in Angular4?
body: <p>I notice that my project has a lot of <strong><a href="https://angular.io/api/router/Resolve" rel="noreferrer">resolver</a></strong> services that despite from working with different entities and repositories host the same code. So I took the challenge to reduce them to a single resolver service using generics:</p>
  
  <pre><code>@Injectable()
  export class DetailResolver&lt;T, R extends Repository&lt;T&gt;&gt; implements Resolve&lt;T&gt; {
  
    constructor(private repositoryService: R, private router: Router) {}
  
    resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable&lt;T&gt; {
      // use repositoryService to resolve this route
    }
  }
  </code></pre>
  
  <p>The entity type T and the repository type R can be specified. However I have trouble using this service:</p>
  
  <pre><code>const appRoutes: Routes = [
    // other routes
    {
      path: ':id',
      component: MessageEditComponent,
      resolve: {
        message: DetailResolver&lt;Message, MessageService&gt;
      }
    }
  ];
  
  @NgModule({
    imports: [
      RouterModule.forChild(appRoutes)
    ],
    exports: [
      RouterModule
    ],
    providers: [
      DetailResolver&lt;Message, MessageService&gt;
    ]
  })
  </code></pre>
  
  <p>As soon as I specify the generic type in <code>DetailResolver&lt;Message, MessageService&gt;</code> the compiler wants me to create an instance:</p>
  
  <blockquote>
    <p>Value of type typeof DetailResolver is not callable. Did you mean to
    include new?</p>
  </blockquote>
  
  <p>I am not really familiar with angular4 DI internals. Can anybody describe whats wrong, is there any solution to this problem? I am using angular 4.3.</p>