Business Object design for WebForm and WinForm...
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngarchitecture' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Mark Feinholz
I've got business objects (custom objects, collections of objects,
hierarchies, etc) that I want to use for both web apps and windows apps.
They use a helper object that takes care of talking to the sql server
database (sets up parameter lists, builds commands, etc). This helper
object (SqlPersist) is instanciated by the Update method at the top of
the object tree - it will contain the open SqlConnection and
SqlTransaction objects and it will get passed on down through the
hierarchy as Update methods are run on all of the dirty objects.

I would like to be able to cache the arrays of parameters that the
helper object builds for each update request in a Hashtable whose key is
the Stored Procedures name so that if there is 50 objects in one of the
collections in the hierarchy, each object's Update method doesn't have
to rebuild the exact same array of SqlParameters - but instead can just
look it up and update it's Value.

So, my question, does anyone know how I can write code that can detect
whether or not the client application for these business objects that
are using the SqlPersist helper object is an asp.net application or not?
I would like to use asp.net's Cache if it is a Web App and use an
internally managed cache if it is not.

Thanks, Mark.
Reply to this message...
 
    
Brian Espey
why not configure the helper object with a custom
cache object up front, passing an instance into the
helper object constructor? you could define an
interface IParameterCache, and then two different
classes, one that implements this interface by making
calls to the asp.net cache object, the other
internally manages the cache. make the helper object
constructor take a parameter of type IParameterCache
and have the client (webform or winform) construct the
object it wants the helper to use. the helper object
doesn't know which type of cache it's talking too; it
just knows how to use the IParameterCache interface.

Brian

--- Mark Feinholz <Click here to reveal e-mail address> wrote:
[Original message clipped]

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

Reply to this message...
 
    
Matthew Tamm
Business Object design for WebForm and WinForm...Hi Mark,

You could look for a HttpContext like so:

public static bool IsHttp()
{
return (System.Web.HttpContext.Current != null) ? true : false;
}

hth

Matt
----- Original Message -----
From: Mark Feinholz
To: aspngarchitecture
Sent: Tuesday, July 09, 2002 1:20 AM
Subject: [aspngarchitecture] Business Object design for WebForm and WinForm...

I've got business objects (custom objects, collections of objects, hierarchies, etc) that I want to use for both web apps and windows apps. They use a helper object that takes care of talking to the sql server database (sets up parameter lists, builds commands, etc). This helper object (SqlPersist) is instanciated by the Update method at the top of the object tree - it will contain the open SqlConnection and SqlTransaction objects and it will get passed on down through the hierarchy as Update methods are run on all of the dirty objects.

I would like to be able to cache the arrays of parameters that the helper object builds for each update request in a Hashtable whose key is the Stored Procedures name so that if there is 50 objects in one of the collections in the hierarchy, each object's Update method doesn't have to rebuild the exact same array of SqlParameters - but instead can just look it up and update it's Value.

So, my question, does anyone know how I can write code that can detect whether or not the client application for these business objects that are using the SqlPersist helper object is an asp.net application or not? I would like to use asp.net's Cache if it is a Web App and use an internally managed cache if it is not.

Thanks, Mark.

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives
Reply to this message...
 
    
Brian Bilbro (VIP)
Business Object design for WebForm and WinForm...You can use the following code:

if(System.Web.HttpContext.Current!=null)
{
// Here you can use
// System.Web.HttpContext.Current.Cache
// or
// System.Web.HttpContext.Current.Application
}
else
{
// Your not in an ASP.NET environment
// and you'll have to create your own
// caching mechanism
}

HTHs,
Brian
----- Original Message -----
From: Mark Feinholz
To: aspngarchitecture
Sent: 07/09/2002 2:20 AM
Subject: [aspngarchitecture] Business Object design for WebForm and WinForm...

I've got business objects (custom objects, collections of objects, hierarchies, etc) that I want to use for both web apps and windows apps. They use a helper object that takes care of talking to the sql server database (sets up parameter lists, builds commands, etc). This helper object (SqlPersist) is instanciated by the Update method at the top of the object tree - it will contain the open SqlConnection and SqlTransaction objects and it will get passed on down through the hierarchy as Update methods are run on all of the dirty objects.

I would like to be able to cache the arrays of parameters that the helper object builds for each update request in a Hashtable whose key is the Stored Procedures name so that if there is 50 objects in one of the collections in the hierarchy, each object's Update method doesn't have to rebuild the exact same array of SqlParameters - but instead can just look it up and update it's Value.

So, my question, does anyone know how I can write code that can detect whether or not the client application for these business objects that are using the SqlPersist helper object is an asp.net application or not? I would like to use asp.net's Cache if it is a Web App and use an internally managed cache if it is not.

Thanks, Mark.
Reply to this message...
 
    
Mark Feinholz
Brian,

The problem with that is the business object is calling the helper
object - not the webForm/winForm client application. So now I'm adding
the complexity of instanciating my business objects with an additional
cache object for caching SqlServer parameters? That doesn't feel right.

-----Original Message-----
From: Brian Espey [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 09, 2002 6:21 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Re: Business Object design for WebForm and
WinForm...

why not configure the helper object with a custom
cache object up front, passing an instance into the
helper object constructor? you could define an
interface IParameterCache, and then two different
classes, one that implements this interface by making
calls to the asp.net cache object, the other
internally manages the cache. make the helper object
constructor take a parameter of type IParameterCache
and have the client (webform or winform) construct the
object it wants the helper to use. the helper object
doesn't know which type of cache it's talking too; it
just knows how to use the IParameterCache interface.

Brian

--- Mark Feinholz <Click here to reveal e-mail address> wrote:
[Original message clipped]

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

| [aspngarchitecture] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Russ McClelland
VGhlIHRlcm5hcnkgb3BlcmF0b3IgaW4gdGhpcyBleGFtcGxlIGlzIHJlZHVuZGFudDoNCiANCnB1
YmxpYyBzdGF0aWMgYm9vbCBJc0h0dHAoKQ0Kew0KICAgIHJldHVybiBTeXN0ZW0uV2ViLkh0dHBD
b250ZXh0LkN1cnJlbnQgIT0gbnVsbDsNCn0NCiANCldoeSBkbyB0aGUgY2hlY2sgdHdpY2UuLi4N
Cg0KCS0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tIA0KCUZyb206IE1hdHRoZXcgVGFtbSANCglT
ZW50OiBUdWUgNy85LzIwMDIgNzozNyBBTSANCglUbzogYXNwb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a problem. maybe you could
combine what others suggested with this approach, so
that you determine the correct IParameterCache object
to create within the SQLHelper class:

public class SQLHelper
{
private IParameterCache mCache;

SQLHelper()
{
if (IsHttp())
mCache = new HttpCacheWrapper();
else
mCache = new CustomCache();
}
}

this way at least you only have to worry about talking
to one cache interface throughout your SQLHelper
component.

it just seems wierd to me to have a class concerned
with SQL to be making decisions based on the existence
of a web context. I thought it might make sense to
make the SQLHelper completely unaware of its context,
but I guess it would be even more unnatural to force
the business objects to pass the sql parameter cache
through.

actually, since you have to write your own cache
object anyway, why don't you just use that in every
case? it's going to have to provide the same
functionality you're using from the asp.net cache
anyway....

Brian

--- Mark Feinholz <Click here to reveal e-mail address> wrote:
[Original message clipped]

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

Reply to this message...
 
    
Paul D. Murphy
The Microsoft application block for data caches parameters. I think you =
would find great value in looking at this wonderfully designed block of =
code. You might want to scrap yours or at least use the source as a =
reference for building a rock solid SQLHelper class.

Paul

http://download.microsoft.com/download/visualstudionet/daabref/rtm/nt5/en=
-us/DataAccessApplicationBlock.msi

Paul D. Murphy
Click here to reveal e-mail address
"Teamwork is a lot of people doing what I say."
-----Original Message-----
From: Mark Feinholz [mailto:Click here to reveal e-mail address]=20
Sent: Tuesday, July 09, 2002 2:20 AM
To: aspngarchitecture
Subject: [aspngarchitecture] Business Object design for WebForm and =
WinForm...

I've got business objects (custom objects, collections of objects, =
hierarchies, etc) that I want to use for both web apps and windows =
apps.=A0 They use a helper object that takes care of talking to the sql =
server database (sets up parameter lists, builds commands, etc).=A0 This =
helper object (SqlPersist) is instanciated by the Update method at the =
top of the object tree - it will contain the open SqlConnection and =
SqlTransaction objects and it will get passed on down through the =
hierarchy as Update methods are run on all of the dirty objects.
I would like to be able to cache the arrays of parameters that the =
helper object builds for each update request in a Hashtable whose key is =
the Stored Procedures name so that if there is 50 objects in one of the =
collections in the hierarchy, each object's Update method doesn't have =
to rebuild the exact same array of SqlParameters - but instead can just =
look it up and update it's Value.
So, my question, does anyone know how I can write code that can detect =
whether or not the client application for these business objects that =
are using the SqlPersist helper object is an asp.net application or =
not?=A0 I would like to use asp.net's Cache if it is a Web App and use =
an internally managed cache if it is not.=A0=20

Thanks, Mark.=20
| [aspngarchitecture] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngarchitecture.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
 
System.Data.SqlClient.SqlConnection
System.Data.SqlClient.SqlTransaction
System.Web.HttpContext




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com