locked
Access session state variable from another assembly RRS feed

  • Question

  • User691781567 posted

    Hi,

    Following multi-tier design I have a data access layer in a separate assembly. Essentially it provides factory classes and classes that map to the database. For this I'm using NHibernate. On top of that runs an ASP.NET website that allows data entry and display.

    Now, I would like to be able to write the currently logged in user to the database for most data classes. However, the current user is only known in the session of the ASP.NET application.

    The only options I see at the moment is either passing the session object or the user object to the Save() method of the data objects. Or is there a better way to do this?

    I would prefer calling

    SomeDataClass.Save();

    to

    SomeDataClass.Save(user);

    But from the Save() method of SomeDataClass I have no access to any session-level variables (it's even in a separate dll, as mentioned before) [:(]

    Suggestions on this issue are very welcome! 

    Kind regards,
    Mark

    Wednesday, March 21, 2007 2:56 PM

Answers

  • User-503940700 posted

    Hi Mark,

    I suggest that you should avoid accessing Session objects in lower layers (its possible but I don't recommend) because it would "break" your "n-tier" concept as your lower layers (like DAL) will become dependent on this Session object which is basically an ASP.NET object. To reduce coupling I suggest that you pass the user related data either through simple variables (like Save(string userId)) or via an user Object, like Save( User u).

    This would make sure that DAL layer is not tightly bound to the GUI.

    Hope this helps,

    Vivek
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 21, 2007 4:31 PM

All replies

  • User-503940700 posted

    Hi Mark,

    I suggest that you should avoid accessing Session objects in lower layers (its possible but I don't recommend) because it would "break" your "n-tier" concept as your lower layers (like DAL) will become dependent on this Session object which is basically an ASP.NET object. To reduce coupling I suggest that you pass the user related data either through simple variables (like Save(string userId)) or via an user Object, like Save( User u).

    This would make sure that DAL layer is not tightly bound to the GUI.

    Hope this helps,

    Vivek
     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 21, 2007 4:31 PM
  • User691781567 posted

    Thanks Vivek,

    I requested the database code developers to create functions like Save(User user) and they did. Took me some time to explain why I wouldn't let them access the session. Now it works flawlessly and it looks like the best solution. [:D]

    Kind regards,
    Mark

    Tuesday, April 3, 2007 4:40 AM
  • User691781567 posted

    Thanks Vivek,

    I requested the database code developers to create functions like Save(User user) and they did. Took me some time to explain why I wouldn't let them access the session. Now it works flawlessly and it looks like the best solution. [:D]

    Kind regards,
    Mark

    Tuesday, April 3, 2007 4:40 AM