You're the first to bring this up, so let's think through what it would take to support it. I'm not super familiar with async controllers, so please bear with me :)
Can you briefly describe:
What default behavior T4MVC currently gives you when you have such asycn controllers, and how it is wrong
What you would expect to be the correct behavior
My guess is that you'd want to refer to it in T4MVC as MVC.MyController.GetSomethingAsync(), but we would want to change the action name to be just 'GetSomething'.
In a sense, it would be similar to what happens today if you put an [ActionName("GetSomething")] attribute on the GetSomethingAsync() method. Actually, it'd be interesting if you could give that a try to verify that it makes it do the right thing.
thanks,
David
Marked as answer by ricka6 on Jul 28, 2011 06:57 PM
Problem is that T4MVC only recognize GetSomethingCompleted() method cause that method returns actualy AsyncResult. It is called when AsyncManager find out that there is no more Outstanding operations to be executed. GetSomethingAsync() in general should
serve as data service ( whatever data is, db i/o ) and through AcynsResult.Parameters collection to pass those data to GetSomethingCompleted() ( for more info on AsyncControler event patern check
http://msdn.microsoft.com/en-us/library/ee728598%28VS.100%29.aspx ).
Problem is that T4Extension methods accept ActionResult object as parameter and because GetSomethingAsync() is void it will not work. On other side you cant call here GetSomethingCompleted() because ActionLink, BeginForm and other methods need to accept
GetSomethingAsync ( as GetSomething ) so correct link can be created.
I will try now [ActionName("GetSomething")] on the GetSomethingAsync() method.
[ActionName("GetSomething")] wont work cause ActionResult is not on GetSomethingAsync but on GetSomethingCompleted. It is not problem with routing mechanism cause when we create rout we put there GetSomething ( without Async ) and rootmanager knows that
he should call GetSomethingAsync(). Solution would be that T4MVC can recognize that there is async controler model in usage here and somehow allow possibility for that to be strongly typed.
Yes, I understand the problem better now. I need to think about how we can support this in T4MVC. It's not totally straightforward with the current model that relies on methods that return ActionResult. I'm thinking og moving away from that model, although
that would lose some benefits like refactoring.
I have done a little hack to exclude AsyncController in ProcessControllerType. I know it doesnt solve the problem but it can help in case that all your controllers aren't inherited from AsyncController.
void ProcessControllerType(CodeClass2 type, AreaInfo area, DateTime controllerLastWriteTime) {
// Only process types that end with Controller
// REVIEW: this check is not super reliable. Should look at base class.
if (!type.Name.EndsWith(ControllerSuffix, StringComparison.OrdinalIgnoreCase))
return;
if (type.IsDerivedFrom["System.Web.Mvc.AsyncController"]) return;
....
If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut. [Albert Einstein]
nikboss
0 Points
3 Posts
Support for AsyncControler
Mar 10, 2010 01:39 PM|LINK
Is there any feature plans to support strongly-typed asyncControlers methods ?
public void GetSomethingAsync(){}
public AsyncResult GetSomthingCompleted(){}
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Support for AsyncControler
Mar 10, 2010 08:38 PM|LINK
You're the first to bring this up, so let's think through what it would take to support it. I'm not super familiar with async controllers, so please bear with me :)
Can you briefly describe:
My guess is that you'd want to refer to it in T4MVC as MVC.MyController.GetSomethingAsync(), but we would want to change the action name to be just 'GetSomething'.
In a sense, it would be similar to what happens today if you put an [ActionName("GetSomething")] attribute on the GetSomethingAsync() method. Actually, it'd be interesting if you could give that a try to verify that it makes it do the right thing.
thanks,
David
nikboss
0 Points
3 Posts
Re: Support for AsyncControler
Mar 11, 2010 07:38 AM|LINK
Problem is that T4MVC only recognize GetSomethingCompleted() method cause that method returns actualy AsyncResult. It is called when AsyncManager find out that there is no more Outstanding operations to be executed. GetSomethingAsync() in general should serve as data service ( whatever data is, db i/o ) and through AcynsResult.Parameters collection to pass those data to GetSomethingCompleted() ( for more info on AsyncControler event patern check http://msdn.microsoft.com/en-us/library/ee728598%28VS.100%29.aspx ).
Problem is that T4Extension methods accept ActionResult object as parameter and because GetSomethingAsync() is void it will not work. On other side you cant call here GetSomethingCompleted() because ActionLink, BeginForm and other methods need to accept GetSomethingAsync ( as GetSomething ) so correct link can be created.
I will try now [ActionName("GetSomething")] on the GetSomethingAsync() method.
nikboss
0 Points
3 Posts
Re: Support for AsyncControler
Mar 11, 2010 07:57 AM|LINK
[ActionName("GetSomething")] wont work cause ActionResult is not on GetSomethingAsync but on GetSomethingCompleted. It is not problem with routing mechanism cause when we create rout we put there GetSomething ( without Async ) and rootmanager knows that he should call GetSomethingAsync(). Solution would be that T4MVC can recognize that there is async controler model in usage here and somehow allow possibility for that to be strongly typed.
davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Support for AsyncControler
Mar 11, 2010 11:34 PM|LINK
Yes, I understand the problem better now. I need to think about how we can support this in T4MVC. It's not totally straightforward with the current model that relies on methods that return ActionResult. I'm thinking og moving away from that model, although that would lose some benefits like refactoring.
David
rstefanca
Member
22 Points
5 Posts
Re: Support for AsyncControler
Nov 27, 2010 10:19 AM|LINK
I have done a little hack to exclude AsyncController in ProcessControllerType. I know it doesnt solve the problem but it can help in case that all your controllers aren't inherited from AsyncController.
void ProcessControllerType(CodeClass2 type, AreaInfo area, DateTime controllerLastWriteTime) { // Only process types that end with Controller // REVIEW: this check is not super reliable. Should look at base class. if (!type.Name.EndsWith(ControllerSuffix, StringComparison.OrdinalIgnoreCase)) return; if (type.IsDerivedFrom["System.Web.Mvc.AsyncController"]) return; ....davidebb
Contributor
7006 Points
1366 Posts
Microsoft
Re: Support for AsyncControler
Nov 29, 2010 08:15 PM|LINK
Yes, I guess we could do this. But even if you don't block the generation, does it actually cause any harm as long as you don't try to use it?