如何使用Global.acax文件声明My类的单个全局实例 [英] How to Declare a single global instance of My class using Global.acax file

查看:133
本文介绍了如何使用Global.acax文件声明My类的单个全局实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个基于Web的应用程序,其中包含一个名为myList的类,该类创建我的收藏夹列表并处理将数据添加到该收藏夹列表中.是否可以声明myList类的全局实例,因此将在Web应用程序启动时创建该实例,并且任何需要访问myList类中的列表的类都可以访问该实例.谢谢

Hi guys i Have a web based application that contains a class called myList that create my collection list and handles adding of data to the collection list. Is it possible to declare a global instance of myList class tht will be created when the web application starts and will be accessible by any class that need to access the list in The myList Class. Thanks

推荐答案

假设可以对您的类进行序列化,则可以将其添加到Application中,从而使该类可用于所有会话.

Assuming your class can be serialzed you can add it to the Application which will make it available to all sessions.

System.Web.HttpContext.Current.Application["SomeClass"] = value; 


这篇关于如何使用Global.acax文件声明My类的单个全局实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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