如何使用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;