Static Business Object work from the UI ASPX code?

G

Guest

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,
 
J

John Saunders

Richard said:
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
 
G

Guest

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,
 
S

Scott Allen

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

Guest

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.
 
S

Scott Allen

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.
 

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

Top