会话外观与ASP.Net中的Singleton对象设计模式 [英] session facade Vs Singleton object design patterns in ASP.Net

查看:65
本文介绍了会话外观与ASP.Net中的Singleton对象设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我ASP.Net中的会话外观类和单一对象设计模式之间哪个更好?另外,请说明建议使用特定设计模式的方案。



谢谢

解决方案

最大的区别在于对象的生存期和隔离度。 Session数据上的外观仍将具有只能由单个用户的Session访问的数据,并且在Session拆除后将消失。单例将持续到应用程序的整个生命周期,并且可以在所有会话中访问。



如果您不太谨慎,Singleton可以使您陷入线程问题,因此,除非有令人信服的理由,否则您应该更喜欢Session数据而不是Singleton。 p>

Can any one tell me which one is better between "Session Facade Class" and "Singleton Object" design patterns in ASP.Net? Also, please state the scenarios where specific design pattern is advisable to use.

Thanks

解决方案

The big differences will be in the lifetime and isolation of the objects. A facade over Session data will still have data that is only accessible by a single user's Session and will die once the Session is torn down. Singletons will last for the lifetime of the application and be accessible across all Sessions.

Singleton's can get you into threading problems if you are not very careful and thus, you should prefer Session data over a Singleton unless you have compelling reasons to do otherwise.

这篇关于会话外观与ASP.Net中的Singleton对象设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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