Home All Groups Group Topic Archive Search About

What would be a good design for my application

Author
7 Jan 2006 7:21 PM
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?

Author
8 Jan 2006 1:43 AM
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.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





Show quoteHide quote
"GS" <n*@no.com> wrote in message
news:uoW2X%237EGHA.648@TK2MSFTNGP14.phx.gbl...
> 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?
>
>
Are all your drivers up to date? click for free checkup

Author
8 Jan 2006 2:03 AM
Peter Bromberg [C# MVP]
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quoteHide quote
"GS" wrote:

> 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?
>
>
>
Author
8 Jan 2006 2:10 AM
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?


Show quoteHide quote
"Peter Bromberg [C# MVP]" <pbromberg@yahoo.nospammin.com> wrote in message
news:B09229ED-096B-4934-AA45-43FB031D40D5@microsoft.com...
> 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
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "GS" wrote:
>
>> 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?
>>
>>
>>
Author
8 Jan 2006 2:52 AM
Peter Bromberg [C# MVP]
Safe to read? Certainly. It's writing where you need to worry about thread
safety.
Of course, you could also just store the property values directly in
Application state such as

Application["serverName"]="myserver";

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quoteHide quote
"GS" wrote:

> 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?
>
>
> "Peter Bromberg [C# MVP]" <pbromberg@yahoo.nospammin.com> wrote in message
> news:B09229ED-096B-4934-AA45-43FB031D40D5@microsoft.com...
> > 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
> >
> > --
> > Co-founder, Eggheadcafe.com developer portal:
> > http://www.eggheadcafe.com
> > UnBlog:
> > http://petesbloggerama.blogspot.com
> >
> >
> >
> >
> > "GS" wrote:
> >
> >> 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?
> >>
> >>
> >>
>
>
>

Bookmark and Share