title: How to send KendoUI data source OData parameters to an abstract RESTful AngularJS data factory?
body: <p>Some time ago, I setup an abstract data factory in AngularJS, and need a hint on how to simplify its use.  I was initially under the impression that I would create another factory per entity that would be called from an AngularJS controller.  Turns out it just looks too complicated and I would like to remove the intermediary entity factory (<code>ContentTypesFactory</code>), and simply call the abstract factory directly from the AngularJS controller.</p>
  
  <p>In the following example I'm wiring up a KendoUI datasource.</p>
  
  <p>AbstractRepository.js:</p>
  
  <pre><code>app.factory('abstractRepository', [function () {
  
      // we will inject the $http service as repository service
      // however we can later refactor this to use another service
      function abstractRepository(repositoryService, whichEntity, odataUrlBase) {
          //this.http = $http;
          this.http = repositoryService;
          this.whichEntity = whichEntity;
          this.odataUrlBase = odataUrlBase;
          this.route;
      }
  
      abstractRepository.prototype = {
          getList: function () {
              return this.http.get(this.odataUrlBase);
          },
          get: function (id) {
              return this.http.get(this.odataUrlBase + '/' + id);
          },
          insert: function (entity) {
              return this.http.post(this.odataUrlBase, entity);
          },
          update: function (entity) {
              return this.http.put(this.odataUrlBase + '/' + entity.ID, this.whichEntity);
          },
          remove: function (id) {
              return this.http.delete(this.odataUrlBase + '/' + id);
          }
      };
  
      abstractRepository.extend = function (repository) {
          repository.prototype = Object.create(abstractRepository.prototype);
          repository.prototype.constructor = repository;
  
      }
  
      return abstractRepository;
  
  }]);
  </code></pre>
  
  <p>ContentTypesFactory.js:</p>
  
  <pre><code>/// &lt;reference path="../Scripts/angular.min.js" /&gt;
  /// &lt;reference path="../app.js" /&gt;
  /// &lt;reference path="AbstractRepository.js" /&gt;
  
  // each function returns a promise that can be wired up to callback functions by the caller
  // the object returned from the factory is a singleton and can be reused by different controllers
  app.factory('contentTypesRepository', ['$http', 'abstractRepository', function ($http, abstractRepository) {
  
      var odataUrlBase = '/odata/ContentTypes'
      var whichEntity = 'ContentTypes';
  
      function contentTypesRepository() {
          abstractRepository.call(this, $http, whichEntity, odataUrlBase);
      }
  
      abstractRepository.extend(contentTypesRepository);
  
      return new contentTypesRepository();
  
  }]);
  </code></pre>
  
  <p>ContentTypesController.js:</p>
  
  <pre><code>app.controller('contentTypesController', ['$scope', '$log', 'contentTypesRepository',
      function ($scope, $log, contentTypesFactory) {
  
          $scope.odataUrlBase = '/odata/ContentTypes';
          $scope.status;
  
          //
          // Grid
          //
          $scope.contentTypesDataSource = new kendo.data.HierarchicalDataSource({
              type: "odata",
              transport: {
                  create: {
                      url: $scope.odataUrlBase
                  },
                  read: {
                      type: "GET",
                      url: $scope.odataUrlBase,
                      //function (data) {
                          // pass in the URL to the abstract factory                     
                      //},
                      dataType: "json"                                // the default result type is JSONP, but WebAPI does not support JSONP
                  },
                  update: {
                      contentType: "application/json",
  
                      url: function (data) {
                          return $scope.odataUrlBase + '(' + data.ContentTypesId + ')';
                      } . . . 
  </code></pre>
  
  <p>Now, removing the reference to ContentTypesFactory, my new controller code looks like this:</p>
  
  <pre><code>app.controller('contentTypesController', ['http', '$scope', '$log', 'abstractDataFactory',
      // the abstract data factory accepts controller type parameters for RESTful CRUD
  
      function ($scope, $log, abstractDataFactory) {
          //function ContentTypeController($scope) {
  
          var crudServiceBaseUrl = "/odata/ContentTypes";
  
          var odataUrlBase = '/odata/ContentTypes'
          var whichEntity = 'ContentTypes';
  
          // Pulled the following code from the ControlerTypesFactory, but not sure how to implement it in this ContentTypesController:
  
          //function contentTypesRepository() {
          //    abstractRepository.call(this, $http, whichEntity, odataUrlBase);
          //}
  
          //abstractRepository.extend(contentTypesRepository);
          //return new contentTypesRepository();
  
          $scope.greeting = 'Hola!';
  
  
  
          var dataSource = new kendo.data.DataSource({
              type: "odata",
              transport: {
                  read: {
                      url: crudServiceBaseUrl,
                      dataType: "json"
                  },
                  update: { // PUT
                      url: function (data) {
                          console.log(data);
                          dataType: "json"
                          return crudServiceBaseUrl + "(" + data.ContentTypeId + ")";
                      },
                      error: function (e) {
                          console.log("error: " + e);
                      }
                  }, . . .
  </code></pre>
  
  <p>I'm sure the change is not that difficult, but I'm fairly new to Angular.  How can I wire this up so to use the abstract repository, and looking for any other Angular best-practices and naming suggestions?</p>