Mar*_*ser 5 c# asp.net asp.net-mvc session design-patterns
我们正在使用ASP.NET MVC4开发一个项目.在团队的一次会议中,出现了使用Session per request 模式的想法.
我做了一些搜索,并在SO中发现了一些问题 - 一般来说 - 这种模式(如果可能被称为)它表示框架ORM.
一个小例子
//GET Controller/Test
public ActionResult Test()
{
//open database connection
var model = new TestViewModel
{
Clients = _clientService.GetClients(),
Products = _productService.GetProducts()
};
//close database connection
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
没有每个请求的会话:
//GET Controller/Test
public ActionResult Test()
{
var model = new TestViewModel
{
Clients = _clientService.GetClients(), // Open and close database connection
Products = _productService.GetProducts() // Open and close database connection.
};
return View(model);
}
Run Code Online (Sandbox Code Playgroud)
疑惑
看起来你的意思是"每个请求的DB上下文".您可以使用工作单元模式来实现它.
您可以在本文中检查Radu Pascal的简单实现:https: //www.codeproject.com/Articles/243914/Entity-Framework-context-per-request
另一个实现(对于Entity Framework和NHibernate),您可以在ASP.NET Boilerplate中找到更复杂的内容:http://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work
| 归档时间: |
|
| 查看次数: |
1395 次 |
| 最近记录: |