concept session in category dependency injection

appears as: session, A session, session, Sessions
Dependency Injection: Design Patterns Using Spring and Guice

This is an excerpt from Manning's book Dependency Injection: Design Patterns Using Spring and Guice.

  • Not all requests are necessarily part of a session.
  • A session is a kind of store that preserves state between requests.
  • The two logical end points of a session are user login and logout.
  • Figure 5.20. A series of related requests from the same user forms an HTTP session.

    You can visualize a session as made up of multiple independent requests from the same user (as in figure 5.20). In figure 5.21, each instance of a request-scoped object is unique to that request (R1 to R3). But a session-scoped instance is shared across all those requests.

    Figure 5.21. A session is composed of independent requests from a user.

    Sessions are extremely useful for tracking state relative to a specific user, since a session always exists around one user. These uses include:

    Listing 11.8. Session-scoped User tracks information about the current user
    @SessionScoped @NotThreadSafe public class User { private String username; public String getUsername() { return username; } //logs in a user, by setting username to the current session public void login(String username) { this.username = username; } //logs out a user, by clearing username from session public void logout() { this.username = null; } }