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 ke开发者_JAVA百科ep 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?
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.
I agree. It should be the result and not perform the action.
精彩评论