Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 17th, 2010, 12:48 AM
Authorized User
 
Join Date: Dec 2010
Posts: 23
Thanks: 3
Thanked 2 Times in 2 Posts
Default Usefulness of IApplicationSettings interface?

I'm curious about the usefulness of having the IApplicationSettings interface. Since it's in the Infrastructure project, I assume it's meant to be used across multiple separate projects/applications? But since the interface defines strongly-typed Properties, it seems to limit its usefulness? For example, the PayPalBusinessEmail property, if I use this interface in another project, that project might not have the concept of a PayPal Business Email.

It seems like the IApplicationSettings interface should just be a a Get() method and a Set() method to read/write settings? That way it's more portable across different projects? I would love to have strongly-typed application settings, but I don't see how we can have that AND portability across projects?

Something like:

Code:
public interface IApplicationSettings
{
object GetSetting(string name);
void SetSetting(string name, object value);
}
Reply With Quote
The Following User Says Thank You to ksouthworth For This Useful Post:
elbandit (December 17th, 2010)
  #2 (permalink)  
Old December 17th, 2010, 12:53 AM
Authorized User
 
Join Date: Dec 2010
Posts: 23
Thanks: 3
Thanked 2 Times in 2 Posts
Default

Or maybe this:

Code:
    public interface IApplicationSettings
    {
        T GetSetting<T>(string name);
        void SetSetting<T>(string name, T value);
    }
Reply With Quote
The Following User Says Thank You to ksouthworth For This Useful Post:
elbandit (December 17th, 2010)
  #3 (permalink)  
Old December 17th, 2010, 04:54 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi ksouthworth,

Good point, you could still have strongly-typed application settings by creating a constants class for your setting names.

In the infrastructure project (shared across different projects) you would place your new IApplicationSettings interface.

Code:
   public interface IApplicationSettings
   {
       T GetSetting<T>(string name);
       void SetSetting<T>(string name, T value);
   }
In an assembly specific to the project you would create a key class:

Code:
    
    public static class ApplicationSettingKeys
    {
        public static readonly string PayPalEmail = "Email@Address.com";
    }
So you could then use them together like so:

Code:
 
var payPalEmail = AppSettings.GetSetting<String>(ApplicationSettingKeys.PayPalEmail);
Good stuff

Cheers
Scott
Reply With Quote
The Following User Says Thank You to elbandit For This Useful Post:
ksouthworth (December 17th, 2010)
  #4 (permalink)  
Old December 17th, 2010, 08:25 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Regarding your first point I'm not sure that the IApplicationSettings interface is designed to be used across multiple applications in the sense you mean. I see it more as designed to enable you to change the way settings are stored for a particular app.

For example we recenlty had a web app that stored many settings in the web.config. This became difficult to manage as access to the system was limited so we changed to storing the data in a database table. Having an interface like IApplicationSettings makes this sort of change much simpler.
__________________
Joe
http://joe.fawcett.name/
Reply With Quote
  #5 (permalink)  
Old December 17th, 2010, 11:36 AM
Authorized User
 
Join Date: Dec 2010
Posts: 23
Thanks: 3
Thanked 2 Times in 2 Posts
Default

Joe,
I guess it depends on how you view the purpose and intention of the "Infrastructure" project. If you want it to be used across multiple future projects, then I think the version of the interface with methods, along with Scott's changes, makes the most sense. If you only intend to use the Infrastructure among a single application's projects (e.g. Agatha's storefron) then keeping the interface with strongly typed properties works just fine.

I definitely agree that the purpose of the interface should allow the persistence strategy of the settings to be swapped out, like you described with using a database backend instead of web.config.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Role of interface ajit Java Databases 1 July 1st, 2006 08:15 PM
Multilanguage Interface tiyyob .NET Framework 2.0 1 June 14th, 2006 01:03 AM
interface with these networks saish Other Programming Languages 0 May 22nd, 2006 01:13 AM
interface and EnterpriseServices ruirui .NET Web Services 0 November 26th, 2003 01:32 PM
Regarding Interface ndr1977 BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 July 30th, 2003 09:56 AM



All times are GMT -4. The time now is 02:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.