如何从层访问Web应用程序层之下会话值 [英] How to access Session values from layers beneath the web application layer

查看:105
本文介绍了如何从层访问Web应用程序层之下会话值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在我们的应用中有许多情况下,我们希望能够访问像当前登录的用户ID在我们的业务领域和数据访问层的东西。在日志中我们推动这个信息到会话,所以我们所有的前端code的访问是很容易的过程。但是,我们有越来越在我们的应用程序的底层数据庞大的问题。我们似乎无法找到一种方法来存储在具有全局范围内只为用户的业务领域(价值静态类和属性由应用程序域,这意味着所有用户会话中的份额,当然共享只是一个该对象的副本)。我们曾考虑过在会议上对我们的业务类,但随后我们的域名是非常紧密耦合到我们的Web应用程序。我们要保持的一个WinForms版本前进的应用成为可能的前景。

We have many instances in our application where we would like to be able to access things like the currently logged in user id in our business domain and data access layer. On log we push this information to the session, so all of our front end code has access to it fairly easily of course. However, we are having huge issues getting at the data in lower layers of our application. We just can't seem to find a way to store a value in the business domain that has global scope just for the user (static classes and properties are of course shared by the application domain, which means all users in the session share just one copy of the object). We have considered passing in the session to our business classes, but then our domain is very tightly coupled to our web application. We want to keep the prospect of a winforms version of the application possible going forward.

我觉得很难相信,我们是第一个人有这种问题。你是如何在你的应用程序中处理这个问题呢?

I find it hard to believe we are the first people to have this sort of issue. How are you handling this problem in your applications?

推荐答案

我不认为有业务类依赖一个全局对象是很大的一个想法,如果可能会避免。您的的是注入必要的信息放进去 - 这使得他们更加可测试的,可扩展的

I don't think having your business classes rely on a global object is that great of an idea, and would avoid it if possible. You should be injecting the necessary information into them - this makes them much more testable and scalable.

因此​​,而不是直接传递会话对象给他们,你应该包裹起来,你需要到存储库类的信息获取方式。业务层可以使用库类作为数据源(呼叫的getUser()就可以了,例如),同时仓库为您的Web应用程序可以使用会话检索要求信息(返回 _session.User.Identity )。

So rather than passing a Session object directly to them, you should wrap up the information access methods that you need into a repository class. Your business layer can use the repository class as a data source (call GetUser() on it, for example), and the repository for your web app can use session to retrieve the requested information (return _session.User.Identity).

当它移植到的WinForms,干脆直接用新的WinForm中心级存储库接口(即的getUser()返回用户主要的Windows版本)。

When porting it to winforms, simply implement the repository interface with a new winform-centric class (i.e. GetUser() returns the windows version of the user principal).

这篇关于如何从层访问Web应用程序层之下会话值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆