开发者

How to fetch session values inside Business Logic Layer?

开发者 https://www.devze.com 2023-01-13 03:41 出处:网络
Good day. I have to pass the session value to 开发者_如何学Pythona business logic layer, I can pass it to the function from presentation layer but how can I access it directly in my business logic lay

Good day. I have to pass the session value to 开发者_如何学Pythona 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.


I would recommend to not access Session from within the business logic layer. The intention of having separate layers is that they serve different purposes. For example the business logic layer should not - generally speaking - contain any reference to the user interface technology, e.g. Session in this case.

The translation from the presentation layer (aka UI Layer) to what the business layer expects should be done in the presentation layer. Who knows? Maybe next week your boss asks you to move the business logic off that web server and onto an application server and use WCF based communication between them.

Clear separation keeps more (all?) of the paths open for tomorrow even if you don't know how tomorrow will look like.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号