mvp session response request

核能气质少年 提交于 2020-01-05 10:34:57

问题


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:


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.



来源:https://stackoverflow.com/questions/3098747/mvp-session-response-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!