Last post Mar 02, 2017 03:04 AM by Chris Zhao
Feb 24, 2017 09:22 PM|krisrajz|LINK
I have a controller with a bunch of methods.
I have a dashboard page which calls (Ajax) these methods, when each of the method is called an instance of controller is created and then the method is called. this results in lots of round trip.
I am thinking something like this:
Controller c=new Controller();
How could I achieve this? (all calls made on a single instance of the controller)
Feb 25, 2017 07:23 AM|raju dasa|LINK
AFAIK, Each request is convert to a thread which can work on application, here new controller instance is created every time.
Even if you create an instance manually, you may not be able to reuse it.
Anyway check the code in this post:
a better option might be using websockets.
Feb 25, 2017 09:18 AM|PatriceSc|LINK
It likely means that you actually have toi change your Ajax API as you find possible to call multiple controller methods in a single go.
If you never get a result without getting some other result you should likely return them as part of a single Ajax call. If doing multiple calls to get the same kind of items you should likely have an API call that would allow to get a list of items.
Thjis way you'll need less API calls to retrieve the same data (ie chunky over chatty API).
Mar 02, 2017 03:04 AM|Chris Zhao|LINK
ApiController's are instantiated by WebApi per request, so we can't very well create it once and reuse it. Moreover, there may be many running concurrently in response to multiple requests, and clearly they must not share state.