namespace AV.Connections
{
protected class MyConnection
{
protected ConnectionStringSettings connectionSettings
{
get { return ConfigurationManager.ConnectionStrings["mySQLConnection"]; }
}
protected DbConnection connection
{
get { return new OdbcConnection(connectionSettings.ConnectionString); }
}
protected DbCommand command
{
get { return connection.CreateCommand(); }
}
protected DbParameter parameter
{
get { return command.CreateParameter(); }
}
}
}
我试图创建一个singleton类,它可以返回连接对象以及其他相关对象。以上就是我想到的方法。我肯定我错了。请指出怎么做?或者如果不是的话,最好的方法是什么。
这不是singleton……我理解,但我认为我不能声明类static,因为它涉及连接。所以我对这种情况很困惑。