Search code examples
c#sessionbusiness-logic

Should Business layer of the application be able to access Session object?


Say you have 3 layers: UI, Business, Data.

Is that a sign of poor design if Business layer needs to access Sessions? Something about it doesn't feel right. Are there any guidelines to follow specifically tailored to web app?

I use c# 2.0 .net


Solution

  • My feeling is that the business layer is the only place to put the session data access because it really is part of your logic. If you bake it into the presentation layer, then if you change where that data is stored (lets says, you no longer want to use session state), then making a change is more difficult.

    What I would do is for all the data that is is session state, I'd create a class to encapsulate the retrieval of that data. This will allow for future changes.

    Edit: The UI should only be used to do the following: 1. Call to the business layer. 2. Interact with the user (messages and events). 3. Manipulate visual object on the screen.

    I have heard people consider the session data access as part of the data layer, and this is semantic, and depends on what you consider the data layer.