title: Multiple instances of provider in Angular 4
body: <p>I created an Angular 2 library for work that helps with creating workflows/state machines. My issue is that I cannot create multiple instances of WorkflowService` foe each workflow in my application. </p>
  
  <p>It is encapsulated in its own module that the consumer can <code>import</code> into their <code>ngModule</code> like so:</p>
  
  <pre><code>@NgModule({
    imports: [
      WorkflowModule.forWorkflow({
        name: 'Turnstile',
        initialStage: 'Locked',
        transitions: [
          {
            name: 'Coin',
            from: ['Locked', 'Unlocked'],
            to: 'Unlocked',
          },
          {
            name: 'Push',
            from: 'Unlocked',
            to: 'Locked'
          }
        ]
      })
    ],
    exports: [WorkflowModule]
  })
  export class TurnstileWorkflowModule {}
  </code></pre>
  
  <p>Internally, the <code>forWorkflow</code> method looks like this:</p>
  
  <pre><code>static forWorkflow(config: WorkflowConfig): ModuleWithProviders {
      return {
        ngModule: WorkflowModule,
        providers: [
          { provide: WORKFLOW_CONFIG, useValue: config },
          { provide: WorkflowService, useClass: WorkflowService },
        ]
      };
    }
  </code></pre>
  
  <p>The issue with this current setup is that it doesn't allow me to have multiple instances of the <code>WorkflowService</code>. How can I reconfigure this to have multiple instance for each consumer?</p>
  
  <p>Thanks!</p>
  
  <hr>
  
  <p>UPDATE: 
  Thanks to @jonrsharpe for the help. I've updated the code but now my application won't compile with AOT.</p>
  
  <p>Here's what the code looks like:</p>
  
  <pre><code>export class WorkflowProvider {
    public static forWorkflow(config: WorkflowConfig): Provider {
      return {
        provide: WorkflowService,
        useValue: workflowFactory(config),
        deps: [Injector]
      };
    }
  }
  </code></pre>
  
  <p>the factory:</p>
  
  <pre><code>export function workflowFactory(config: WorkflowConfig) {
    return function (injector: Injector) {
      return new WorkflowEngine(config, injector);
    };
  }
  </code></pre>
  
  <p>The error that I'm receiving:</p>
  
  <blockquote>
    <p>ERROR in Error: Error encountered resolving symbol values statically.
    Function calls are not supported. Consider replacing the function or
    lambda with a reference to an exported function (position 9:10 in the
    original .ts file), resolving symbol workflowFactory</p>
  </blockquote>