|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
What would be a good design for my applicationHi,
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? You'd be better of utilizing shared/static objects so that
your assemblies work in more than just a web environment. 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? > > 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 -- Show quoteHide quoteCo-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? > > > 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? >> >> >> 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"; -- Show quoteHide quoteCo-founder, Eggheadcafe.com developer portal: http://www.eggheadcafe.com UnBlog: http://petesbloggerama.blogspot.com "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? > >> > >> > >> > > >
Other interesting topics
remember me cookie in asp .net
Problem compiling remote web in VS2005 WebPartManager: disable Personalization and still use WebPartManger.AddWebPart() WebPartManager.AddWebPart...not understanding exception ASP:TableRow with dynamic design Asp.net And Firefox dynamic column/fields Memebership, Role, Profile Provider Hirarchical View in GridView compiling and building VS2005 webprojet for framework 1.1 |
|||||||||||||||||||||||