且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以使用ASP.NET会话[]变量外部DLL

更新时间:2023-02-15 23:38:28

您应该能够使用HttpContext.Current.Session

You should be able to use HttpContext.Current.Session

虽然是我同意你不应该紧密结合你的业务逻辑DAL或等组件,以ASP.Net会话。有很多有效的情况下访问一个Web项目以外的HTTP上下文。

While yes I agree you should not tightly couple your Business Logic DAL or etc assemblies to ASP.Net session. There are plenty of valid cases for accessing HTTP Context outside of a web project.

Web控件是probally的一个***的例子,可重复使用的HTTP模块等等...

Web Controls is probally one of the best examples, reusable http modules etc etc...

现在,如果你希望你的DLL从拉届东西一个选择是抽象出来的​​会话。所以,你可以像定义一个的IStorage接口,那你的图书馆将知道如何使用。然后你就可以有一个或sessionStorage的类MemoryStorage并使用IoC容器注入合适的类到你的库类。这给了你***code是你怎么想它是codeD而不会占用你的code到会话。哦,和另外一个好处,如果处理得当可以用来不会配合你的code到会议网站无论是。

Now one option if you want to have your DLL pull the stuff from Session is to abstract out session. So you could define an interface like IStorage, that your library will know how to use. Then you can have a SessionStorage or MemoryStorage class and use IoC to inject the appropiate class into your library classes. This gives you the freedom to code it how you wanted it to be coded without tying your code to Session. Oh and one other benefit if done properly can be used to not tie your code to session in the web either.