Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

When I'm using a ASP.NET MVC controller with AngularJS, then my controller mostly contains JSON result functions. And then when I create my AngularJs service its allways the same code to write the service for Get or POST calls to my ASP.NET controller functions.

MVC Home Controller Functions:

[AngularCreateProxy]
public JsonResult InitUnitTestPersonEntry()
{
    return Json(new PersonEntry(), JsonRequestBehavior.AllowGet);
}

[AngularCreateProxy]
public JsonResult InitUnitTestSearchModel()
{
    PersonSearchModel searchModel = new PersonSearchModel() {Name = String.Empty};
    return Json(searchModel, JsonRequestBehavior.AllowGet);
}

[AngularCreateProxy]
public JsonResult AddUnitTestPerson(PersonEntry entry)
{
    PersonEntries.Add(entry);
    return Json(entry, JsonRequestBehavior.AllowGet);
}

My automaticly created AngularJS Home Service:

function homePSrv($http, $log) { 
    this.log = $log, this.http = $http; 
}

homePSrv.prototype.InitUnitTestPersonEntry = function () {
   return this.http.get('/Home/InitUnitTestPersonEntry').then(function (result) {
      return result.data;
   });
}

homePSrv.prototype.InitUnitTestSearchModel = function () {
    return this.http.get('/Home/InitUnitTestSearchModel').then(function (result) {
        return result.data;
    });
}

homePSrv.prototype.AddUnitTestPerson = function (entry) {
    return this.http.post('/Home/AddUnitTestPerson',entry).then(function (result) {
      return result.data;
    });
}

angular.module("app.homePSrv", [])
   .service("homePSrv", ['$http', '$log', homePSrv]);

I've written my own little "proxy" (don't know if this is the right naming) which automaticly creates a angularJS service for my controller JSON result functions as new javaScript file - that works fine so far.

my question are:

Whats the right way to handle this task is there some GitHub Projekt out there which supports this allready or how are you solving this "problem"?

Whats the right naming because I can't find anything about this solution and I don't know if "proxy" is right?

share|improve this question
1  
Check out the ASP.NET Boilerplate project, specifically this page - aspnetboilerplate.com/Pages/Documents/Dynamic-Web-API - which documents how the framework dynamically creates angular controllers. – MattSull Apr 28 at 20:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.