My.Settings in a class library project?

Z

Zoe Hart

Prior to VS2005 I configured my applications via the appSettings section of
the app.config file. When I developed a class library, I used
ConfigurationManager.AppSettings(settingName) syntax and the compiler didn't
care that no such settings existed yet. The settings were ultimately managed
in the app.config file of the host applicaton that used the classes in the
library.

I'm not sure how to handle configuration settings for a class library with
the new My.Settings feature.

If I don't set the settings up in the class library project the
My.Settings.SettingName syntax complains that SettingName is not a member of
My.Settings. But the class library will never execute outside the context of
some other application and that other application really "owns" the
configuration settings. So do I set them up in the class library just for
compile purposes and then set them up again in the host application and, at
runtime will the host application settings be the ones that the class
library classes actually honor?

Thanks,
Zoe
 
G

Guest

I don't know the answer to your question, but to me it's more of an design
issue. You should think of class libraries of being very generic or as I like
to call "dumb and stupid". What I mean by this is that they should have NO
configuration settings. ALL configuration settings should come from the
calling application. This is easily done by adding them as parameters to
constructions, methods or even using properties. I prefer the constructor way
of doing it because it forces the use of the parameters that usually are
required. This way, your class library can now be used by different
applications that can easily change the configuration as needed.

======================================
David McCarter
www.vsdntips.com
VSDN Tips & Tricks .NET Coding Standards available at:
www.cafepress.com/vsdntips.20412485
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top