Business Logic

M

Mike

Hello,

I am working on a ASP.NET 1.1 project and would like to set up the web
application to only have one unique Business Logic object that is created
when the client connects. I would like to avoid re-instantiating the object
every time a page is loaded (the connection to the DB are currently in a
PageBase class). I basically would like to be able to re-use the web pages,
call "generic" methods on my Business Logic, so that the web application can
be re-used among other projects that need to display the same information.
In WinForms I would do that in the entry point of the application, but I am
not really sure how to do it in ASP.NET/

Any suggestion?

Thanks.
Mike
 
G

Guest

You can load objects at the start of the application or the start of a
session (whether the logic is the same for one session or all sessions).
Using a static object (Shared in VB.NET), you can set up an Application
scoped object without a lot of work. Simply add a property for the object to
global.asax.{language abbrev.} and fill in the Application_Start event.

The Singleton pattern is essentially the same, although the static object is
held inside the Singleton code.

Across applications is more difficult. You can "share session" across
multiple apps, but you cannot share session objects. This means you have to
persist the data and refresh in each application. As long as the data is
static, you do not have a problem; if it changes often, you are better to
grab and cache the data on a regular cycle (how often depends on the
freshness requirements of the app)>

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
S

sloan

To follow up on Cowboy's post.

I have a web singleton at:
http://sholliday.spaces.msn.com/ 10/24/2005 entry.

I am using the Session object, its easily converted to an Application
object.

Here are the changes to make... from the code you can get from the blog:


private static string WEB_APPLICATION_OBJECT_GUID =
"D777D4C2-1576-40C3-88F8-FA16E94DDC90";
private static WebApplicationDataStore singletonInstance = null;
private Hashtable m_memoryStore = null;

private WebApplicationDataStore()
{
this.m_memoryStore = new Hashtable();
}

public static WebApplicationDataStore GetInstance()
{
if (null != System.Web.HttpContext.Current )
{
if (null != System.Web.HttpContext.Current.Application )
{
if (null !=
System.Web.HttpContext.Current.Application[WEB_APPLICATION_OBJECT_GUID] )
{
singletonInstance =
((WebApplicationDataStore)(System.Web.HttpContext.Current.Application.Get(WE
B_APPLICATION_OBJECT_GUID)));
}
}
}
if ((singletonInstance == null))
{
singletonInstance = new WebApplicationDataStore();

System.Web.HttpContext.Current.Application.Add(WEB_APPLICATION_OBJECT_GUID,
singletonInstance);
}
return singletonInstance;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top