5
An idea arose among the developers to use the standard of Session per request - Session by request.
Researching on the subject, I found some topics in the OS that generally said that the indication was for frameworks ORM.
Small practical example
//GET Controller/Teste
public ActionResult Teste()
{
//abrir conexão com o banco
var model = new TesteViewModel
{
ListaClientes = _servicoCliente.ObterClientes(),
ListaProdutos = _servicoProduto.ObterProdutos()
};
//fechar conexão com o banco
return View(model);
}
Without the Session per request:
//GET Controller/Teste
public ActionResult Teste()
{
var model = new TesteViewModel
{
ListaClientes = _servicoCliente.ObterClientes(), // Abro e fecho a conexão com o banco no inicio e fim do método, respectivamente.
ListaProdutos = _servicoProduto.ObterProdutos() // Abro e fecho a conexão com o banco no inicio e fim do método, respectivamente.
};
return View(model);
}
Questions:
- To contextualize, as the request session consists?
- It’s a good solution?
- What would be the best way to implement? Open the connection via web even?
- Recommended for projects with complex queries/operations?
- There is a chance of a competition problem when there are transactions/transactions involved?
Questions 2, 3 and 4 give a lot of room for opinion.
– Jéf Bueno