I am trying to build a generic connection class using DbProviderFactory, DbConnection and other abstract classes in System.Data.Common
I noticed that both DbProviderFactory and DbConnection have method to Create Command.
If I intend to implement Singleton pattern, on which object is it advisable (on DbProviderFactory object or DbConnection object)?
You use the
DbProviderFactories
class to produce aDBProviderFactory
for your chosen connector. Using this, and your connection string, you create aDbConnection
. With thisDbConnection
you can create yourDbCommand
and use theDbProviderFactory
to create yourParameter
and add them. There's no need for a singleton.