tag:blogger.com,1999:blog-15136575.post7472768416025178840..comments2023-10-17T12:00:16.772+01:00Comments on Code rant: Taking the HttpContext out of the MVC Framework ControllerMike Hadlowhttp://www.blogger.com/profile/16441901713967254504noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-15136575.post-41051603602151966172011-06-01T10:10:16.531+01:002011-06-01T10:10:16.531+01:00Thanks Mike. I would also do the same with IPrinci...Thanks Mike. I would also do the same with IPrincipal for accessing the current User (httpContext.User).Ben Fosternoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-80661368815248718002008-08-22T17:19:00.000+01:002008-08-22T17:19:00.000+01:00I totally agree that "it's often useful to be able...I totally agree that "it's often useful to be able to access the HttpContext in a controller and this method gives a far more IoC friendly design."<BR/><BR/>On our MVC project we're trying to avoid validation on the properties. However, our properties are more suited toward real world domain objects (Order, Address, etc). We feel that these properties shouldn't contain validation since the validation is basically business rules. You SearchCriteria object though... I can buy the validation going in those properties.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-64177877064007176542008-08-22T10:40:00.000+01:002008-08-22T10:40:00.000+01:00Chris,You are right, I could have used the binding...Chris,<BR/><BR/>You are right, I could have used the binding stuff in MvcContrib and simply had the criteria as the argument for my test.<BR/><BR/>The main issue I have with that approach is that I like to have my validation rules in property setters, which is the obvious place for them. I've written a custom binder, the validatingBinder in the example which can handle the validation exceptions generated by the property setters. In this example I haven't shown the exception handling but if you get the suteki shop code there are plenty of examples there.<BR/><BR/>You might argue that I would have been better off implementing my own controller base class and putting the custom binding logic in that, but I haven't quite got that far yet. I really need to look closer at how the MvcContrib ConventionController does.<BR/><BR/>But it doesn't alter the point that it's often useful to be able to access the HttpContext in a controller and this method gives a far more IoC freindly design.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-62634087665345500622008-08-21T20:40:00.000+01:002008-08-21T20:40:00.000+01:00Can't you just pass in your criteria through the A...Can't you just pass in your criteria through the Action without pulling it in through the Request? This would be easier to test and you wouldn't have to mock the HttpContext at all. I'm still kind of new to MVC so maybe I missed a previous blog post...Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-79251232723427963562008-08-21T09:55:00.000+01:002008-08-21T09:55:00.000+01:00You just have to love Monorail for using IHttpStuf...You just have to love Monorail for using IHttpStuffAdapters everywhere ... ;)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-84541338499621137692008-08-20T15:07:00.000+01:002008-08-20T15:07:00.000+01:00Hi Stefan,Thanks for that. I think we're on the sa...Hi Stefan,<BR/><BR/>Thanks for that. I think we're on the same wavelength.<BR/><BR/>Yes, looking forward to ALT.NET UK :)Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-62573798846339180932008-08-20T14:59:00.000+01:002008-08-20T14:59:00.000+01:00Hello Mike,I did the same for the Session object a...Hello Mike,<BR/><BR/>I did the same for the Session object and blogged about it here (in german of course): http://www.lieser-online.de/blog/?p=82<BR/><BR/>Cheers,<BR/>Stefan<BR/><BR/>P.S. See you on ALT.NET UK!!Anonymousnoreply@blogger.com