Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
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);
}
The Following User Says Thank You to ksouthworth For This Useful Post:
elbandit (December 17th, 2010)
 
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);
    }
The Following User Says Thank You to ksouthworth For This Useful Post:
elbandit (December 17th, 2010)
 
Old December 17th, 2010, 04:54 AM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
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 protected]";
    }
So you could then use them together like so:

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

Cheers
Scott
The Following User Says Thank You to elbandit For This Useful Post:
ksouthworth (December 17th, 2010)
 
Old December 17th, 2010, 08:25 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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/
 
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.





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





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