Support for Task<ActionResult>

Apr 26, 2012 at 10:51 PM

I've found T4MVC to be an awesome tool, however I've recently switched to using the new C# 5 async/await paradigm and MVC's new Task<ActionResult>, but it seems T4MVC doesn't pick up methods with that new return type.  Any idea when that update will be coming?

Coordinator
Apr 26, 2012 at 11:43 PM

Here was an old thread, though that was not with the Task<T> pattern http://forums.asp.net/t/1534619.aspx

I think doing it for Task<T> would be more feasible than with the other pattern, because the method doesn't return void. But it's also not completely straightforward, as we'd need to generate classes that extend Task<T>, the same way that we generate classes that extend ActionResult today.

If someone wants to have a go at it... :)

 

Oct 15, 2012 at 2:54 AM

Just wondering has there been anything new with this?  Can we use async keyword with T4MVC yet?

Coordinator
Oct 19, 2012 at 1:13 AM

Sorry, short answer is that there isn't. :(

Apr 24, 2013 at 8:36 AM
Hello,
I'm going to give this a go, shouldn't be too hard.
Just need to change the T4 to support generating a overridden method for Task<ActionResult> but require it to return a Task.FromResult(actionresult) instead, then need to update the extensions to support Task<ActionResult>.

Cheers,

Kev
Apr 24, 2013 at 11:17 AM
I was just looking for this too actually.
I think there are going to be more and more people using Task<ActionResult> with asp.net MVC, especially considering that entity framework 6 will support async save and async query so that should have a knock-on effet all the way to most controller actions...
Apr 24, 2013 at 3:20 PM
I've added some code to the T4 template today that allows creation of ActionResults for Task based actions - https://t4mvc.codeplex.com/SourceControl/network/forks/kev_bite/T4mvcTaskBasedActions

Just need to create the extensions method for all the Task<ActionResult> overloads.
Apr 24, 2013 at 10:11 PM
Thanks kev_bite, nice job. I hope that makes it back to the master and official nugget.
Coordinator
Apr 24, 2013 at 11:16 PM
Please make sure to send a PR when you have a changes that's ready to go.
May 9, 2013 at 12:08 PM
Hey kev_bite, I've seen you've done some progress.
Do you need some help to get that completed? I'd be happy to help if you need, but I'm not sure if you have some pending changes in your local copies...
May 10, 2013 at 3:39 PM
Hello,
Its all should be complete and merge in.

Cheers,

Kev
Coordinator
May 10, 2013 at 8:38 PM
Actually, Kev's code has been in T4MVC since 3.6, so you should be able to use it today!
Coordinator
May 10, 2013 at 8:39 PM
Here was the pull request.
May 11, 2013 at 5:02 AM
That's awesome thanks guys!