Structural question regarding scope of variables
- From: Froefel <hansdeschryver@xxxxxxxxx>
- Date: Wed, 01 Aug 2007 16:00:49 -0000
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?
.
- Follow-Ups:
- Re: Structural question regarding scope of variables
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: Structural question regarding scope of variables
- Prev by Date: Re: Adding a property at runtime
- Next by Date: Re: Structural question regarding scope of variables
- Previous by thread: datetime with offset > local and utc
- Next by thread: Re: Structural question regarding scope of variables
- Index(es):
Relevant Pages
|