在类库访问会话。 [英] Access session in class library.

查看:118
本文介绍了在类库访问会话。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发使用2个子项目中的应用程序架构:
   一)asp.net web应用程序(它涵盖了用户界面和业务逻辑)和
   B)类库。 (它包括数据访问层)

I am developing an application architecture that uses 2 sub projects: a) asp.net web application (it covers user interface and business logic) and b) class library. (it covers data access layer)

在系统用户成功登录时,用户信息被存储在会话对象

After system user successfully logs in , the user information is stored in a session object.

我现在面临的问题是,当我尝试访问类库项目(数据访问层)会话对象,它总是返回null。

The problem I am facing is when I try to access that session object in class library project(data access layer), it always returns null.

我需要访问类库项目中的会话对象,因为在我的情况下,每个用户都有自己的用户名和密码的数据库访问(出于安全原因);

I need to access the session object in class library project because, in my case each user has their own username and password for database access(for security reasons);

那么,如何如何阅读和类库项目写入自/至会话对象。

So, How how do i read and write from/to session object in class library project

推荐答案

首先,作为围正确地注意到了 - 你需要重新考虑一下,如果有对每个用户单独的数据库登录是一个好主意 -​​ 因为你松散连接池(不同的用户将不能够重复使用现有的连接 - 和创建一个新的SQL连接是相当昂贵)

First of all, as Peri correctly noticed - you need to think again if having separate database logins for each user is a good idea - because you loose connection pooling (different users won't be able to reuse existing connections - and creating a new sql connection is quite expensive).

如果你真的想保持独立的数据库用户,我会创建数据访问接口来抽象会话:

If you really wish to keep separate database users, I would create interface to abstract session from data access:

public interface ILoginDataService
{
   LoginData Current { get; }
}

和实施将从会议通过登录数据。在这种方式,你将不必依赖会话会话在数据访问逻辑 - 所以这将是更容易测试,还你会分离关注

And implementation would pass login data from session. In such way you won't have session dependency to session in your data access logic - so it will be more testable, also you'll separate concerns.

这篇关于在类库访问会话。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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