One reason I use the constructor, is to be able to switch up which db I
might use.
Or instance.
class UserInfo
{
private string m_connectString = string.Empty;
//constructor1
public UserInfo()
{
//no connection string was given , so read it from the config
if (null!=Configur ation["MyAppConnectio nString"]) // The syntax if
off here, I"m going from memory, but the object which reads config file
AppSettings
{
this.m_connectS tring=Configura tion["MyAppConnectio nString"];
}
else
{
throw new ArgumentExcepti on("MyAppConnec tionString not defined in config
file");
}
}
//constructor2
public UserInfo(string connectString)
{
this.m_connectS tring=connectSt ring;
}
}
I actually don't do that anymore, as I use the EnterpriseLibra ry
dataconfigurati on.config, but I use the same concept.
Anyway, I am just posting a reason why you might consider a instaniated
object with multi constructors.
...
My code runs against multiple databases (where a database is a client, but
the clients all have copies of the same db model) ... since I write good
data layer objects, I like to be able to send in alternate connectionStrin gs
as needed. The overloaded constructor does this, but has the "easy
constructor", if I don't send it in.
"Mark Gilkes" <ma*********@NO SPAMgmail.com> wrote in message
news:14******** *************** ***********@mic rosoft.com...
I would just like to get a feeling for what others are doing here. Having
read through the 'Data Tiers' paper under MS's Paterns and Practices I am
designing and developing a small(ish) 3 layered web app. Now I've come to
design the DALC classes I cannot see any reason why I would make these
methods instance methods. It seems to me that they only need be static
methods. The DALC is purely a class definition with a bunch of methods
that call on stored procs and return DataSets. I can't see any reason for
constructor code here or any inheritance, therefore all these methods
could be static right?
--
MG