title: AngularJS injecting a factory into a provider
body: <p>I'm building a module which must use the <code>provider</code> recipe as it requires configuration before runtime. I'm interested in modularizing my code, so I would like to inject some services into the provider. I'm aware that injecting <code>providers</code> into other <code>providers</code> is simple, but seems to be overkill for what I am trying to achieve, so I would like to inject a <code>factory</code> instead. </p>
  
  <p>From what I understand, using the <code>$injector</code> during a runtime gives us access to the <code>instanceCache</code> through angular's <code>createInternalInjector</code> method which returns services which have been instantiated. </p>
  
  <p>When using the <code>$injector</code> during the config phase, you get access to the <code>providerCache</code> which holds uninstantiated services.</p>
  
  <p>I feel like this assumption must be incorrect though. In the code below, the <code>$injector</code> is being used in a provider but through a function that is called during the application's run phase. I would hope to get access to the <code>instanceCache</code> but I am only given access to the <code>providerCache</code> through the <code>$injector.get</code> method. </p>
  
  <pre><code>_tudModule.factory('wfTabletUsageDataCache', [
          function () {
              return {
                  addToLog: fn () { … }
              }
          }
  ])
  
  
  _tudModule.provider('$tabletUsageData', [
      '$injector', function $tabletUsageDataProvider ($injector) {
  
      function getCacheFactory() {
         return $injector.get('wfTabletUsageDataCacheProvider').$get();
      }
  
      function logInteraction(state, buttonId) {
          getCacheFactory().addToLog();           // fn() called
      }
  ]);
  </code></pre>
  
  <p>What about the <code>$injector</code> in a <code>provider</code> disables access to the <code>instanceCache</code>? Even when the methods in the provider are not being run during the <code>config</code> phase? </p>
  
  <p>Also, I haven't seen the method I am using <code>$injector.get('wfTabletUsageDataCacheProvider').$get()</code> before. Though it works, is this a bad way to achieve such functionality?</p>
  
  <p>Thanks for any direction. </p>