jeudi 2 février 2017

How does it work the Session Per Request pattern?

We're working on a project using ASP.NET MVC4. In one of team's meeting, came out an idea of using Session per request pattern.

I did a little search and found out some questions here in SO saying - in general - that this pattern (if may be called) it's indicated to frameworks ORM.

A little example

//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);
}

Without session per request:

//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);
}

Doubts

  1. To contextualize, how does session per request works?
  2. Is it a good solution?
  3. What is the best way to implement it? Open the connection on web?
  4. Is it recommended in projects with complex queries / operations?
  5. Is there a possibility of giving a concurrency problem when transactions are involved?

Aucun commentaire:

Enregistrer un commentaire