我们正在使用ASP.NET MVC4进行项目开发。在团队会议中,提出了使用“每个请求一个Session”模式的想法。
我进行了一些搜索,并在这里找到了一些问题,通常说,这种模式适用于ORM框架。
以下是一个小例子:
我进行了一些搜索,并在这里找到了一些问题,通常说,这种模式适用于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);
}
没有每个请求的会话:
//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);
}
疑问
- 为了解释背景,会话每请求(session per request)是如何工作的?
- 它是一个好的解决方案吗?
- 最佳实现方式是什么?在 web 上打开连接?
- 在涉及复杂查询 / 操作的项目中推荐使用吗?
- 当涉及事务时是否可能出现并发问题?