I am trying to build a session/tempdata provider that can be swapped. The default provider will work on top of asp.net mvc and it needed to access the .net mvc TempData from the business object class. I know the tempdata is available through the controller context, but i cant seem to find if that is exposed through HttpContext or something. I dont really want to pass the Controller context as an argument as that would dilute my interface definition since only asp.net based session prov开发者_如何学Cider needs this, other (using NoSQL DB etc) doesn't care about Controller Context.
To clarify further, adding little more code here. my ISession interface look like this. and when this code goes to production, the session/tempdata is expected to work using NoSql db. But i also like to have another implementation that works on top of asp.net mvc session/tempdata for my dev testing etc.
public interface ISession
{
T GetTempData<T>(string key);
void PutTempData<T>(string key, T value);
T GetSessiondata<T>(string key);
void PutSessiondata<T>(string key, T value);
}
I don't know exactly what you are trying to do but TempDataDictionary implements IDictionary<string, object>
so you could have your business objects take it as parameter or use constructor injection. Then you could have your controller pass the TempData as parameter to the business object. By using the dictionary interface your business objects no longer depend on ASP.NET MVC.
精彩评论