Good day. I have to pass the session value to a business logic layer, I can pass it to the function from presentation layer but how can I access it directly in my business logic layer ? Also is it a good approach to pass it directly to business logic layer like
GetMyRecords(Count,Session["userID"].toString()); ?
As per John’s reply above, you ideally do not want to access any UI elements in your business layer.
You should pass the session values from your presentation layer to the business layer so that the business layer is only aware of the values – not where they are coming from.
As regards your second point about how to pass the values from presentation layer
I would suggest you should atleast wrap Session[“userID”].toString()) as a property in your presentation layer.
Because its a property, you can add checking / validation logic if needed.
Also, i find it cleaner to have a wrapper SessionWrapper class and use that in the application for accessing the session values. The advantage of this is that if your Session Persistence changes, its usually a one place change. Of course, this is not necessary as the .NET Session Providers can be plugged in via configuration even if you create your own provider.