What would be a good design for my application

G

GS

Hi,

I'd rather start from a good design and go from there so would be greatfull
for any input.
I have a simple ASP.NET application and would like to make solution elegant.
I store settings in web.config file and I would like to have class in my
application which will hold application level objects.
Some methods of the class will be executed in different threads and some
properties are shared among threads and static in nature.
So what I want to do is to initialize and object in global.asax and assign
those global variables there. My question does this sound a good design?
Do I store this object of this class in Application variable? How this will
survive multithreading?
What would be the sample code I have to put in Global.asax to initialize
this object?
 
R

Robbe Morris [C# MVP]

You'd be better of utilizing shared/static objects so that
your assemblies work in more than just a web environment.
 
G

Guest

GS,
What you describe is somewhat contradictory. You talk of a "simple ASP.NET
application" but then you go on to say that "Some methods of the class will
be executed in different threads and some properties are shared among threads
and static in nature." -- which does not sound "simple" at all.

There is no reason why you cannot store application level objects in
Application state, and create these objects in Application_Start in Global.
However, if you are sure that multiple threads may be accessing your
object(s) at the same time, then you'll need to add locking code to prevent
collisions.

Hope that helps.
Peter
 
G

GS

Ok. I have a class with couple of static method and some properties.
I'd like to access those properties through entire ASP.NET application, for
example I'll store servername in one of the properties. I'll initialize
object of this class during Application_OnStart event and store in
Application variable. Will it be safe to read those properties through
entire application?
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top