Jay,
Thanks a lot for the pointers.
I added some Properties to my Base page and it works perfectly.
After some playing around I decided to offer the 2 choices (Session of file
serialization) and configured the Property Gets and Sets to check the config
file to see which way to handle it.
I appreciate the help!
--
Joe Fallon
"Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in message
news:u%23yFbrjLEHA.2012@TK2MSFTNGP11.phx.gbl...[color=blue]
> Joe,
> It really depends on how your Domain objects are organized.
>
> If a Domain object is strictly used by a single Page, I would put the
> property in that page's code behind, if it is used by a group of pages,[/color]
then[color=blue]
> I would add a second layer base class for that group of pages. Note: I[/color]
would[color=blue]
> consider 2 pages a group! ;-) For example PageBase is the base page for[/color]
all[color=blue]
> web forms, while TeamPageBase is the base page for "team" web forms, and
> UserPageBase is the base page for "user" web forms. Which means both
> TeamPageBase & UserPageBase inherit from PageBase.
>
> Alternatively if there is a root Domain object that all other Domain
> objects, my PageBase would offer this root...
>
> As far as configurable, generally I "configure" it when I design the[/color]
class.[color=blue]
> This Domain object will always be X, hence my sample is Session, changing[/color]
it[color=blue]
> to Y, would be a design change, based on performance data collected from
> running the app. Design changes would require a recompile of the VS.NET
> project & redistribute.
>
> If there was a design requirement for it to be "user admin" configurable,
> then I would look at creating a provider of sorts, where the web.config[/color]
had[color=blue]
> an entry for what provider to use, and there would be providers for[/color]
Session,[color=blue]
> Viewstate, Cache, Application, and etc...
>
> The provider would follow the Plug-in pattern, similiar to the provider
> pattern in ASP.NET 2.0
>
>[/color]
http://msdn.microsoft.com/library/de...sp02182004.asp[color=blue]
>
> Note if I supported the provider option, the settings in the web.config
> would be in a custom configuration section.
>
> I would not use a select case in this case, as Select cases are not OO...
> However that is a different discussion. See
>
http://www.refactoring.com/catalog/r...ymorphism.html
> for a start on that discussion ;-)
>
> Hope this helps
> Jay
>
> "Joe Fallon" <jfallon1@nospamtwcny.rr.com> wrote in message
> news:ucYACrgLEHA.3712@TK2MSFTNGP11.phx.gbl...[color=green]
> > Jay,
> > I have a Page base class for my app so what you are saying makes sense.
> >
> > Since I could have dozens (or hundreds) of Business Objects, do you[/color][/color]
think[color=blue][color=green]
> > the idea of using a Property for each one of them makes sense in the[/color][/color]
Base[color=blue][color=green]
> > class or should I have a Property on the given page that consumes the[/color][/color]
BO?[color=blue][color=green]
> >
> > Also, I noted that in the sample Property there was just the use of[/color]
> Session.[color=green]
> > Are you saying that you would just edit the Property and change it to
> > Viewstate if you wanted to change how it is stored?
> > But wouldn't that require you to re-compile and re-distribute the
> > application .dll?
> >
> > I am wondering if it makes sense to be more "configurable" and set flags[/color]
> in[color=green]
> > web.config and then use SelectCase in the Property Get/Set to determine[/color]
> the[color=green]
> > value of the flag and implement any of these:
> > Application, Cache, Session, Viewstate.
> >
> > Then a client who is low on RAM could switch the flag in web.config from
> > UseSession to UseFiles (or somethinng like that - maybe an Enum) and the[/color]
> app[color=green]
> > would behave differently without a re-compilation.
> >
> > What do you think?
> > --
> > Joe Fallon
> >
> >
> >
> > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
message[color=blue][color=green]
> > news:#K0NiSfLEHA.3684@TK2MSFTNGP12.phx.gbl...[color=darkred]
> > > Doh!
> > > I should add: All web forms within my web app would inherit from the
> > > PageBase class, as I showed for WebForm1.
> > >
> > > Hope this helps
> > > Jay
> > >
> > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in[/color][/color]
> message[color=green][color=darkred]
> > > news:Odkw72eLEHA.2244@tk2msftngp13.phx.gbl...
> > > > Joe,
> > > > Basically its an extension of the Encapsulate Downcast refactoring.
> > > >
http://www.refactoring.com/catalog/e...eDowncast.html
> > > >
> > > > Rather then have the DirectCast of Session variables scattered[/color]
> > throughout[color=darkred]
> > > my
> > > > code, I encapsulate the downcast into a property, normally in a base
> > > class.
> > > >
> > > > Normally something like:
> > > >
> > > > ' in PageBase.vb file
> > > > Public Class PageBase
> > > > Inherits System.Web.UI.Page
> > > >
> > > > Public Property ShoppingCart() As ShoppingCartDataSet
> > > > Get
> > > > Return DirectCast(Session("ShoppingCart"),
> > > > ShoppingCartDataSet)
> > > > End Get
> > > > Set(ByVal value As ShoppingCartDataSet)
> > > > Session("ShoppingCart") = value
> > > > End Set
> > > > End Property
> > > >
> > > > End Class
> > > >
> > > >
> > > > ' in WebForm1.aspx.vb
> > > > Public Class WebForm1
> > > > Inherits PageBase
> > > >
> > > > Private Sub Page_Load(...) Handles MyBase.Load
> > > > DataGrid1.DataSource = Mybase.ShoppingCart.Items
> > > > DataGrid1.DataBind()
> > > > End Sub
> > > >
> > > > End Class
> > > >
> > > > ' in WebForm1.aspx
> > > > <%@ Page Language="vb" AutoEventWireup="false"
> > > Codebehind="WebForm1.aspx.vb"
> > > > Inherits="SampleWebApp.WebForm1" %>
> > > >
> > > >
> > > > Where ShoppingCartDataSet is a typed dataset that represents the[/color]
> > shopping[color=darkred]
> > > > cart.
> > > >
> > > > Benefits of the above include, but are not limited to:
> > > > - Session Variable name is in a single location
> > > > - Easy to change from Session to Cache or Disk & back
> > > > - Downcast is in a single location
> > > > - Enables dynamic creation, the Get could create & initialize the[/color]
> > Session[color=darkred]
> > > > variable if it did not already exist
> > > > - The code that consumes the Session variable is cleaner (there is[/color][/color][/color]
no[color=blue][color=green][color=darkred]
> > > > downcast & checks)
> > > >
> > > > If your case, the check of the web.config setting would be in a[/color][/color][/color]
single[color=blue][color=green][color=darkred]
> > > spot,
> > > > the property's Get & Set methods.
> > > >
> > > > Even if the Session variable is used in a single location I would[/color]
> > probably[color=darkred]
> > > > apply the same pattern, as invariable the session variable winds up[/color]
> > being[color=darkred]
> > > > used in multiple places, its more consistent with other code, and it
> > > > promotes "cleaner" code.
> > > >
> > > > Hope this helps
> > > > Jay
> > > >
> > > > "Joe Fallon" <jfallon1@nospamtwcny.rr.com> wrote in message
> > > > news:%23HN%23ngeLEHA.1192@TK2MSFTNGP11.phx.gbl...
> > > > > Jay,
> > > > > That is very interesting.
> > > > > Session, Viewstate, Cache, Application,
> > > > >
> > > > > Can you elaborate on how you control these with some sample code?
> > > > >
> > > > > I am sure it is not an "all or nothing" solution. You must be able[/color][/color]
> to[color=green][color=darkred]
> > > > > control a given variable (like my large collection) using any one[/color][/color][/color]
of[color=blue][color=green][color=darkred]
> > > > > Session, Viewstate, Cache, Application. I would like to see how[/color][/color][/color]
you[color=blue]
> do[color=green][color=darkred]
> > > it
> > > > so
> > > > > I don't go down the wrong path again!
> > > > >
> > > > > Thanks for another good idea!
> > > > >
> > > > > --
> > > > > Joe Fallon
> > > > >
> > > > >
> > > > >
> > > > > "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@msn.com> wrote in
> > > message
> > > > > news:uRivVYeLEHA.2716@tk2msftngp13.phx.gbl...
> > > > > > Joe,
> > > > > > > So instead of the normal 2 lines of code (1 to put the object[/color][/color]
> into[color=green][color=darkred]
> > > > > Session
> > > > > > > and 1 to take it out)
> > > > > > > I just wrap them in an If statement and check the flag.
> > > > > > I hope you encapsulated your If in a property in a well known[/color][/color]
> place.[color=green][color=darkred]
> > > > > >
> > > > > > In fact I normally encapsulate all access to Session, Viewstate,
> > > Cache,
> > > > > > Application, & etc variables in properties in a well known[/color][/color][/color]
place.[color=blue][color=green]
> > This[color=darkred]
> > > > > > allows a "single" point of change if I decide that Cache is[/color][/color][/color]
better[color=blue][color=green][color=darkred]
> > > then
> > > > > > Session for the variable...
> > > > > >
> > > > > > This well known place could either be a shared property of a[/color][/color]
> domain[color=green][color=darkred]
> > > > class
> > > > > > (causes coupling to ASP.NET) or a base Page or Control class in
> > > ASP.NET.
> > > > I
> > > > > > normally go for the base Page or Control class, although the[/color][/color]
> domain[color=green][color=darkred]
> > > > class
> > > > > > makes its easier (the property is in a single place, verses two
> > > places).
> > > > > > Note there are ways to mitigate the coupling to ASP.NET if you[/color]
> > choose[color=darkred]
> > > to
> > > > > put
> > > > > > the property in the domain class...
> > > > > >
> > > > > > Hope this helps
> > > > > > Jay
> > > > > >
> > > > <<snip>>
> > > >
> > > >
> > >
> > >[/color]
> >
> >[/color]
>
>[/color]