In modern .NET data access (ADO.NET), DbDataSource acts as a factory or a representation of the entire database connection pool, while IDbConnection represents a single, transient network session or actual open connection instance to that database.
Understanding this difference is critical for structuring dependency injection, scaling modern cloud-native apps, and maximizing execution performance. Core Structural Difference DbDataSource (Class) IDbConnection (Interface) What it represents The entire database/pool instance. A single, isolated database connection. Primary purpose Hands out connections and runs standalone commands. Opens, closes, and manages specific transactional state. DI Lifetime Singleton (registered once per database). Transient (created and disposed of per query). Thread Safety Fully Thread-safe. Not Thread-safe. Async Support Fully native async methods built into the class. Lacks built-in async methods (requires casting). IDbConnection: The Legacy Session Model
IDbConnection is an abstraction introduced in the earliest versions of .NET. It defines common methods like Open(), Close(), and BeginTransaction().
Introduce DbDataSource abstraction to System.Data #64812 – GitHub
Leave a Reply