.NET DbProviderFactory and Singleton

1k Views Asked by At

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)?

1

There are 1 best solutions below

2
On

You use the DbProviderFactories class to produce a DBProviderFactory for your chosen connector. Using this, and your connection string, you create a DbConnection. With this DbConnection you can create your DbCommand and use the DbProviderFactory to create your Parameter and add them. There's no need for a singleton.