title: Dynamic provider inside controller in AngularJS
body: <p>when configuring a route, I also configure the settings, a custom property with a object with static values to configure specific operations.</p>
  
  <p>I then have a service class/file that looks like:</p>
  
  <pre><code>(function() {
      'use strict';
  
      angular.module('app.category').factory('categoryservice', categoryservice);
  
      /* @ngInject */
      function categoryservice($http, $location, $q, exception, logger) { 
          var service = {
              getSubMenusInformation: getSubmenuData            
          };
  
          return service;
  
          function getSubmenuData() {
              // 
              return "some data object";
          }
      }
  });
  </code></pre>
  
  <p>on the settings, I would like to have the service class name I would use so in the controller I could instantiate it (without injection) and call the method I want (also in settings) to get some specific data.</p>
  
  <p>something like this:</p>
  
  <pre><code>(function () {
      'use strict';
  
      angular.module('app.core').run(Runnable);
  
      Runnable.$inject = ['$rootScope', 'logger', 'config'];
  
      /* @ngInject */
      function Runnable($rootScope, logger, config) {
          /* jshint validthis:true */
          $rootScope.config = config;
  
          // now, the service is not instantiated yet.
          // he won't know what categoryservice is.
          // so the code is obviously broken at this point.
  
          var some_specific_data = [config.settings.someProviderName].[config.settings.someProviderFunction];        
  
          logger.debug( 'DEBUG MODE IS ON! '+ some_specific_data );
      }
  })();
  </code></pre>
  
  <p>I think this should be done with a provider instead, but I don't have a clue about how, and I got the problem that the service (or provider) name is a string, as also the method I want to call.
  and I don't want to inject it on the controller because it will change with each route.</p>
  
  <p>then I'll worry about running it only once.</p>
  
  <p>does anyone have any ideas about how I can do this or how to do it without breaking the pattern and where?</p>
  
  <p>the final purpose is to load dynamic data for each route "on load" and depending on the settings values (yes it will be slow).</p>
  
  <p>thanks.</p>