470,819 Members | 1,603 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,819 developers. It's quick & easy.

C# Create Global values in DLL?

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?

--
JP
..NET Software Developer
Oct 15 '08 #1
4 2697
You might want to look at:
New! StockTrader 2.02 with Configuration Service Source Code

http://msdn.microsoft.com/en-us/netf.../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.


"JP" <JP@discussions.microsoft.comwrote in message
news:4C**********************************@microsof t.com...
>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?

--
JP
.NET Software Developer

Oct 15 '08 #2
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" wrote:
You might want to look at:
New! StockTrader 2.02 with Configuration Service Source Code

http://msdn.microsoft.com/en-us/netf.../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.


"JP" <JP@discussions.microsoft.comwrote in message
news:4C**********************************@microsof t.com...
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?

--
JP
.NET Software Developer


Oct 15 '08 #3
"JP" <JP@discussions.microsoft.comwrote in message
news:4C**********************************@microsof t.com...
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

--
Mark Salsbery
Microsoft MVP - Visual C++

>
--
JP
.NET Software Developer
Oct 16 '08 #4

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 [MVP]" wrote:
"JP" <JP@discussions.microsoft.comwrote in message
news:4C**********************************@microsof t.com...
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

--
Mark Salsbery
Microsoft MVP - Visual C++


--
JP
.NET Software Developer

Oct 22 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jonathan | last post: by
4 posts views Thread by Andrew V. Romero | last post: by
1 post views Thread by VbUser25 | last post: by
2 posts views Thread by Melson | last post: by
2 posts views Thread by Matthew Hood | last post: by
6 posts views Thread by Andrea Williams | last post: by
5 posts views Thread by Alistair King | last post: by
4 posts views Thread by Dom | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.