In Asp.net MVC one is encouraged to derive custom ActionResults, however should these classes handle other tasks unrelated to views, perhaps a EmailActionResult would render a view then send an email. What is best practice for the class ActionResult, is it only view specific? I want to keep things DRY too. Should the sending of the email be factored into a service class? perhaps using a filter would work. what are your thoughts?
+1
A:
No.
The ActionResult should be the Result of the Action, it should not also perform the action.
In your specific case, you should have refactor the emailsending into a service class and then use the ActionResult to indicate what exactly happened.
I am hard pressed to imagine a "simple" EmailActionResult that is reusable enough to handle different scenarios.
aanund
2009-12-08 08:26:52
agreed, however if it renders a view and accepts a email address then that would be resuable but thats not the point. thanks for your input
almog.ori
2009-12-08 08:47:16
+1
A:
I agree. It should be the result and not perform the action.
George Handlin
2010-02-05 01:11:28