views:

29

answers:

1

Hi, Guys.

I am using the Model-View-Presenter pattern in my project web and now I am with a doubt. How I do to treat session and cookie this scenario? How I do to write file using "Response.WriteFile" for example?

+1  A: 

I think the most typical approach (and, in fact, the one used by ASP.Net MVC) is to wrap the HttpContext in an abstraction (like IContext or something) which exposes whatever subset of context functionality you need to get access to. If your using an IoC container, then you can pretty easily configure an IContext which has a default implementation that just calls HttpContext.Current under the covers. Things start to get a little trickier when you have to reference Session, and Request/Response objects, because you will typically need to wrap those as well (at least if you want to maintain testability in your presenter code). The trick is really to come up with some abstraction that works for you from an API perspective, and then just make that the way you deal with all of the nitty-gritty details.

ckramer
Ok, but is right I set/using data in Session, or Cookie, or Context, or Cache, Response.WriteFile, or Response.Redirect?
Diego Dias
I think it is something that you can't really get away from when your dealing with a Web platform. You should probably try to minimize your use of things like Sessions or Cookies, but there are times when it is the only real option. You could try to abstract a lot of those things away, but in the end your programming for the Web, so your going to have to address them. The key is to try to make sure that your limiting your usage to your Presenters (and Views if you need to read a cookie in javascript or something).
ckramer
Ok. I thought that I should treat session in view because is a necessity of the asp.net. But I should do this in the presenter then, sure?
Diego Dias