class / base class help

R

Rob Meade

Hi all,

Ok - I'm going around in circles and would appreciate some help.

I have written a windows service, which up until I tried to be clever was
working well :blush:)

I have a main class which inherits a base class, I also have a
"configuration" class which stores a load of values read in from an xml file
which I would like to be available at any time (without reading the xml file
again).

My intention was to add my "ApplicationConfiguration.vb" class as an object
in my base class, thus everything that derives from it gets to see the
settings.

My problem being that I have some code in the base class that I would also
like to use in the application configuration class - is only one function
but it writes to the event log and I dont see the point of doubling this
up...

This is where the problem began - I decided it would be best for the
application configuration class to inherited the base class - whooops - and
there we go - .net endless circling and creating more and more instances of
itself until it overflowed....luckily in vs2005 it catches this kinda
stupidity before it happens (2003 didnt!!)...

So, I've now removed the inheritance in the application configuration class,
but I'm left without the function I need...

Can anyone offer me any solutions? A "singleton" was suggested by a
colleague at work, but I hadn't fully explained the problem so I wasn't sure
if that was the way to go - plus I only have a rough idea of what a
singleton is so I'll probably code it all wrong anyway :D

Any help appreciated,

Rob
 
K

Kevin Spencer

I would suggest taking advantage of the System.Configuration namespace.
There's no need to re-invent the wheel, and every ASP.Net app comes with its
own wheel - the web.config file. You can store all kinds of stuff in there,
and it is not read from the file every time you access it. It is cached in
memory when the application starts.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
J

Joshua Mitts

Yes, there is a great ConfigurationSettings / ConfigurationManager (2.0)
class that will do everything for you :)
 
R

Rob Meade

...
I would suggest taking advantage of the System.Configuration namespace.
There's no need to re-invent the wheel, and every ASP.Net app comes with
its own wheel - the web.config file. You can store all kinds of stuff in
there, and it is not read from the file every time you access it. It is
cached in memory when the application starts.

Hi Kevin,

Sorry, I should have explained a little further, part of the solution (the
bit I'm having problems with) is a service, as opposed to being web based,
the config file is installed on to the client machine, it would be
beneficial if this could be then updated later - in addition I'm hoping that
an installer will write values to this file at some stage.

Regards

Rob
 
R

Rob Meade

...
Yes, there is a great ConfigurationSettings / ConfigurationManager (2.0)
class that will do everything for you :)

Hi Joshua,

Thanks for the reply - as per my reply to Kevin, alas this wasn't for a web
based app (not this part anyway) - so I'm reading in an xml file installed
on the client PC.

Regards

Rob
 
K

Kevin Spencer

Heck, that shouldn't stop you. Any type of .Net app can use a configuration
file. In your project, add an App.config file. At compile-time it becomes
applicationName.exe.config.

The only difference between them is the configuration sections they use. You
can even create your own custom configuration sections, section groups, the
whole nine yards.

BTW, if this isn't an ASP.Net app, why are you asking here? Just curiouos.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
K

Kevin Spencer

You can still use a .Net configuration file. See my other reply for details.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
R

Rob Meade

...
Heck, that shouldn't stop you. Any type of .Net app can use a
configuration file. In your project, add an App.config file. At
compile-time it becomes applicationName.exe.config.

aye, but the file needs to be installed on the client PC and updated by
either the client or the installer - I didn't think you'd be able to do this
with the web.config / app.config files (security etc).
BTW, if this isn't an ASP.Net app, why are you asking here? Just curiouos.

The solution is part and part - half web / half windows service - being that
it was a generic class question I figured it would be ok - sorry if not.

Regards

Rob
 

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