global settings question

  • Thread starter Thread starter t f
  • Start date Start date
T

t f

Hi

Okay this should be a simple one...

In my solution i have 2 projects (one class library and one control
library) - they both share the name default namespace - question is I want
to be able to have settings persist for both librarys but have it contained
in one settings files (this is in the class library as the control library
uses the class library)...

i tried the following in the control library

global::mynamespace.Properties.Settings.Default.xxx

but it is inaccessible due to its protection level... how do i make it so
that the librarys share the same Settings?

is it impossible? if so should i just make a static class which returns the
value?

thanks
t f
 
Try using a regular app.config file (assuming you have an executable that
starts up and reads it. If your settings are simple, you can keep them in the
appSettings section and gain access from either class or control library with

ConfigurationManager.AppSettings["settingKey"];

You'll need to add a reference to System.Configuration assembly.
Peter
 
Hi

Thanks :-) I will look into it


Peter Bromberg said:
Try using a regular app.config file (assuming you have an executable that
starts up and reads it. If your settings are simple, you can keep them in
the
appSettings section and gain access from either class or control library
with

ConfigurationManager.AppSettings["settingKey"];

You'll need to add a reference to System.Configuration assembly.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




t f said:
Hi

Okay this should be a simple one...

In my solution i have 2 projects (one class library and one control
library) - they both share the name default namespace - question is I
want
to be able to have settings persist for both librarys but have it
contained
in one settings files (this is in the class library as the control
library
uses the class library)...

i tried the following in the control library

global::mynamespace.Properties.Settings.Default.xxx

but it is inaccessible due to its protection level... how do i make it so
that the librarys share the same Settings?

is it impossible? if so should i just make a static class which returns
the
value?

thanks
t f
 
Hi,

As both projects are libraries (which becomes .DLL) you cannot use an
app.config file.

When I have done in escenarios ilke this is to keep the settings in a file
that I expect to be found in the same folder than the dll. You create a
class with static members and constructor, it's the constructor the one that
load & process the file. Now the issue is that you need to manually process
the file yourself. Not a big deal though.

Take a look at opennetcf.org they provide a similar mechanism of Config than
the full framework.
 
Actually, you can use an app.config file. You just have to use the one
that is associated with the EXE (if there is one). There is nothing that
says that libraries can't use application configuration files, it just
doesn't make sense to have a separate file outside of the application
configuration one.

This is actually the preferred method of using config files. Look at
all the application blocks from MS. IIRC, while they use separate files,
they still are referenced to those separate files from the main app.config
file. Having a separate file which stands ^on it's own with nothing
referencing it^ is not a good thing, as it decentralizes the logical
container for your applciation settings.

What developers need to realize is that even though they are developing
libraries in some cases, those libraries ARE NOT THE APPLICATION.
Therefore, don't assume that you should have your own settings. Rather, let
the person who is putting their application together put their settings
where they would most likely expect it, in the app.config file.
 
Hi,

I'v been employing a singleton object in my solution. And the singleton is
added reference to
all the projects ,so projects can share the global settings of singleton
object.

It seems work well.

BUT,someone told me not to use singleton as global setting.
i cannt find what's the reason excactly.

Anyone tell me why? Thx first.

gshzheng
20070404
 
Back
Top