Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Application level object" 1

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
Is it possible to have an object available to all pages in a given solution? For example if I wanted to store a Database Object and make it available to all pages in my solution but the datasource of that object depended on a selection made by the user, how would I achieve that without passing the object explicitly from page to page?

Thanks for replies
 
you mentioned "page" are you talking about an asp.net application?

if so, the containers break down like this
application: available across all sessions for the life of the application
cache: available across all sessions for the life of the application. values are periodically flushed, so you need to account for that.
session: specific to each user for the life of the application
items: specific to the current request
querystring: self explanatory
form: self explanatory
cookies: self explanatory
params: aggregation of form, querystring, items and cookies

there should be very few, if any objects you store in the cache or application directly.

if you're using an IoC container the typical setup is
Code:
public class Global : HttpApplication
{
   public static IWindsorContainer Container;

   public void Application_Start(object sender, EventArgs e)
   {
         Container = new WindsorContainer();
         //configure container
   }

   public void Application_End(object sender, EventArgs e)
   {
      Container.Dispose();
   }
}
I have found the HttpContext.Items container is a great place to store database connections. You can open a single connection for the length of the request and commit/close at the end. I have an FAQ on this approach. see my signature for the link.

if you want to store user specific values that are relatively static the session is the best choice.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top