Pass Session data to a Class Library without using a bunch of constructors?

Posted by sah302 on Stack Overflow See other posts from Stack Overflow or by sah302
Published on 2010-05-06T17:13:11Z Indexed on 2010/05/06 17:18 UTC
Read the original article Hit count: 219

Hi all,

I've got my application here where literally every object has a lastUpdatedBy property. The information I put into here is the person's username, which is retrieved from the session("username") variable.

How can I pass this data to my DAL in the class library?

At first I was just passing in the value into each method, but this is ridiculous I thought, there should be no reason to do that every time a method is called.

Then I thought well if I just put it in a constructor for each of the DAL related classes, that will make it even easier.

However, even still on any given page, I've got a plethora of New() declarations, for which every single line I need to pass in the session username casted as a string.

Is there an even still more efficient way of doing this so that I could only declare this in one place, and everything will know what it is and I can pass it to classes in a class library?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about session