Hi group,
I've been developing a number of classes, many of which have a similar
structure, as follows:
namespace
{
public class classname
{
Private Fields
private readonly static string connString =
ConfigurationManager.ConnectionStrings["SCMConnectionString"].ConnectionString;
Public Fields
Public Properties
Private Instance Methods
Public Instance Methods
Public Static Methods
// these methods use the connString variable to establish database
connections, using Microsoft.ApplicationBlocks.Data
}
}
However, the static connString is declared in every class. I'm
currently only using one connection, but I foresee using 2 or 3
different connection strings, based on where the data will need to
come from.
Can anyone suggest a better way of doing this, so that I don't have to
declare this variable in every class?
Note that I had considered using inheritance by basing all the classes
that need data on a base class that contains the static connection
string. However, that doesn't seem the right approach because I only
want to achieve the effect of a global variable. Speaking of global
variables, note that I'm targeting a web environment.
Any thoughts on this?