By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,141 Members | 1,223 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,141 IT Pros & Developers. It's quick & easy.

Static Business Object work from the UI ASPX code?

P: n/a
Hi,

I write mostly winform app and often create a Business Class Library for my
bus logic. When doing this I often set the method to static so I don't need
to instantiate the class.

Can I do the same with ASP.Net or will all user end up getting the same copy
for the business object?

Thanks,

--
Richard Beyea

Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,

I write mostly winform app and often create a Business Class Library for
my
bus logic. When doing this I often set the method to static so I don't
need
to instantiate the class.

Can I do the same with ASP.Net or will all user end up getting the same
copy
for the business object?


If your static class has no static (Shared in VB.NET) data, then you don't
have a problem. The problem isn't with static methods, but with static data.

Static data will require synchronization which was not required in Windows
Forms. In a Windows Forms application, only a single thread can access your
static data (unless you spawn off more threads yourself). In an ASP.NET
application, each request comes in on a different thread. Since two requests
can arrive at the same time, this means that two threads can be accessing
your static data at the same time. Without synchronization, you will have
problems which can be very difficult to debug.

John Saunders
Nov 19 '05 #2

P: n/a
Thanks John!

All my data is either Private or exposed in public properties. None is
defined as shared or static. Just the methods are static.

Thanks again,

"John Saunders" wrote:
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,

I write mostly winform app and often create a Business Class Library for
my
bus logic. When doing this I often set the method to static so I don't
need
to instantiate the class.

Can I do the same with ASP.Net or will all user end up getting the same
copy
for the business object?


If your static class has no static (Shared in VB.NET) data, then you don't
have a problem. The problem isn't with static methods, but with static data.

Static data will require synchronization which was not required in Windows
Forms. In a Windows Forms application, only a single thread can access your
static data (unless you spawn off more threads yourself). In an ASP.NET
application, each request comes in on a different thread. Since two requests
can arrive at the same time, this means that two threads can be accessing
your static data at the same time. Without synchronization, you will have
problems which can be very difficult to debug.

John Saunders

Nov 19 '05 #3

P: n/a
That sounds a bit odd, Richard. What can the methods do if all of the data
is in instance fields?

--
Scott
http://www.OdeToCode.com/blogs/scott/
Thanks John!

All my data is either Private or exposed in public properties. None is
defined as shared or static. Just the methods are static.

Thanks again,

"John Saunders" wrote:
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Hi,

I write mostly winform app and often create a Business Class Library
for
my
bus logic. When doing this I often set the method to static so I
don't
need
to instantiate the class.
Can I do the same with ASP.Net or will all user end up getting the
same
copy
for the business object?

If your static class has no static (Shared in VB.NET) data, then you
don't have a problem. The problem isn't with static methods, but with
static data.

Static data will require synchronization which was not required in
Windows Forms. In a Windows Forms application, only a single thread
can access your static data (unless you spawn off more threads
yourself). In an ASP.NET application, each request comes in on a
different thread. Since two requests can arrive at the same time,
this means that two threads can be accessing your static data at the
same time. Without synchronization, you will have problems which can
be very difficult to debug.

John Saunders

Nov 19 '05 #4

P: n/a
The Business Class Library call into a Data dll that accesses an application
server (a COBOL DLL) to return the data I need to display in the UI/ASPX
pages.

"Scott Allen" wrote:
That sounds a bit odd, Richard. What can the methods do if all of the data
is in instance fields?

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #5

P: n/a
Scott,

Is what I am doing wrong?

Thanks for your help!

"Scott Allen" wrote:
That sounds a bit odd, Richard. What can the methods do if all of the data
is in instance fields?

--
Scott
http://www.OdeToCode.com/blogs/scott/


Nov 19 '05 #6

P: n/a
In general if you are using static methods, the class won't have instance
properties and fields (variables). But this is just a general design rule
of thumb and there are always exceptions, it is hard to comment w/o seeing
the code.

--
Scott
http://www.OdeToCode.com/blogs/scott/
Scott,

Is what I am doing wrong?

Thanks for your help!

"Scott Allen" wrote:
That sounds a bit odd, Richard. What can the methods do if all of the
data is in instance fields?

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.