C# Create Global values in DLL?

J

JP

I have a C# DLL project I have created. The DLL plugs into other C#.NET
applications. This DLL has several classes and methods comprised for 4
namespaces that are used by other programmer to perform common tasks.

The settings for this DLL are contained within a SQL a database for easy
modification. The issue I am having is the number of times the DLL has to
make connections to the database to retrieve the settings information because
the call is in a different class or namespace from the previous call.

Ive have tried whenever possible to get the settings information at the
class level rather then the method level so that all methods in the class can
use the same values. However, because these classes are also used by other
methods WITHIN the same DLL, the number of times needed to retrieve
information from SQL continues to grow.

Is there any type of Global access in DLL project that would allow be to
load information one time and have its values accessible to any namespace or
class in the project?
 
S

sloan

You might want to look at:
New! StockTrader 2.02 with Configuration Service Source Code

http://msdn.microsoft.com/en-us/netframework/bb499684.aspx

Greg wrote a "mini configuration framework" piece.
Its NOT super trivial.


Are the settings COMPILED into the dll? Or is the dll a wrapper to read
settings from the database? (and subject to change within the db)?

Can you fill in a few areas of your description of what you're doing now.
 
J

JP

The setting file was originally compiled as an Embedded Resource XML document
in the project, but the need to change settings without redistributing the
DLL arose and now the settings are contained in a SQL table (about 40 values
loaded into a string array).

If it was simply loading the embedded XML document every time I wouldn’t be
nearly as concerned as I am about making repetitive connections to SQL to get
the information.

Say for example a programmer request the use of a method in the DLL. This
method will then access the DLLs database to pull some information it might
need. For simplistic sake lets say this method is contained within the
[Utility.Token] namespace. During the process of this method, an error
occurs. This triggers the stack trace to get handed off to another method in
the SAME DLL but a different namespace [Utility.Errors]. Because all the
setting information is not retained across classes or namespaces, I have to
connect to SQL again to reload the information to process the error that
occurred. Now I potentially have two open database connections (depending on
when I disposed of the first) for information I’ve already loaded once.

I had pondered passing the string array with the settings from method to
method, however, because these methods are used both externally by other
programmers and internally by other classes in the DLL, the programmer in
particular would have no idea how to get (or what) the string[] is.

If I could load an array once when the DLL is loaded (something similar to
Application_Start() (but for a DLL) then I could load a string array and have
it be visible to all objects in the DLL regardless of namespace or class
that’s trying to use it.

Hope this makes since


--
JP
..NET Software Developer


sloan said:
You might want to look at:
New! StockTrader 2.02 with Configuration Service Source Code

http://msdn.microsoft.com/en-us/netframework/bb499684.aspx

Greg wrote a "mini configuration framework" piece.
Its NOT super trivial.


Are the settings COMPILED into the dll? Or is the dll a wrapper to read
settings from the database? (and subject to change within the db)?

Can you fill in a few areas of your description of what you're doing now.
 
M

Mark Salsbery [MVP]

JP said:
I have a C# DLL project I have created. The DLL plugs into other C#.NET
applications. This DLL has several classes and methods comprised for 4
namespaces that are used by other programmer to perform common tasks.

The settings for this DLL are contained within a SQL a database for easy
modification. The issue I am having is the number of times the DLL has to
make connections to the database to retrieve the settings information
because
the call is in a different class or namespace from the previous call.

Ive have tried whenever possible to get the settings information at the
class level rather then the method level so that all methods in the class
can
use the same values. However, because these classes are also used by other
methods WITHIN the same DLL, the number of times needed to retrieve
information from SQL continues to grow.

Is there any type of Global access in DLL project that would allow be to
load information one time and have its values accessible to any namespace
or
class in the project?


Why does the settings info have to be retrieved from a database every time
one of your methods is used?
Can't your classes just retrieve the settings once and cache them, or is the
info different every time?

If all the classes use the same settings data, can you wrap the settings in
a class so all your other classes can access the info from a common point?
You could probably use a static class if there's only one set of setttings.

Mark
 
J

JP

The settings need to be updated from time to time without the need of
reposting or re-distributing the DLL to the people that are using it. In
addition, we don’t want to create an external file for the settings that
would have to be distributed with the DLL.

I need a way of getting the settings to persist across all classes and
namespaces in a given instance of the DLL. As it stands now, anytime I
reference another class in the same instance of the DLL, I have to reload the
settings. Since CLASS B cant see what CLASS A was already doing.




--
JP
..NET Software Developer


Mark Salsbery said:
JP said:
I have a C# DLL project I have created. The DLL plugs into other C#.NET
applications. This DLL has several classes and methods comprised for 4
namespaces that are used by other programmer to perform common tasks.

The settings for this DLL are contained within a SQL a database for easy
modification. The issue I am having is the number of times the DLL has to
make connections to the database to retrieve the settings information
because
the call is in a different class or namespace from the previous call.

Ive have tried whenever possible to get the settings information at the
class level rather then the method level so that all methods in the class
can
use the same values. However, because these classes are also used by other
methods WITHIN the same DLL, the number of times needed to retrieve
information from SQL continues to grow.

Is there any type of Global access in DLL project that would allow be to
load information one time and have its values accessible to any namespace
or
class in the project?


Why does the settings info have to be retrieved from a database every time
one of your methods is used?
Can't your classes just retrieve the settings once and cache them, or is the
info different every time?

If all the classes use the same settings data, can you wrap the settings in
a class so all your other classes can access the info from a common point?
You could probably use a static class if there's only one set of setttings.

Mark
 

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