The basic requirement of this library is to provide an interface containing asynchronous methods that was left out of the original release of System.Data. The primary driver is to provide mocking point for unit testing.
There are three object groups that this library extends.
-
Connection. Connection objects are the entry points to the System.Data namespace. The input parameter is as simple as a connection string and optionally
SqlCredentialinstance forSqlClient. -
Command. Command objects are created from connection objects. The input parameter is the query and the connection object.
-
DataReader. DataReader objects are used to read the output data of the command object.
SqlClient objects are sealed. That means we cannot extend it. This library wraps the SqlClient objects in another object that contains the extension. This is an example of Adapter pattern.
The wrapper classes are located under System.Data.Async.SqlClient. SqlConnectionAsync wraps SqlConnection, SqlCommandAsync for SqlCommand, and finally SqlDataReaderAsync for SqlDataReader. In version 2.x, we moved from deriving the wrappers from abstract DbConnection, DbCommand, and DbDataReader to a simpler, shallower class hierarchy.
Guidelines:
- Wrapper constructor takes the same parameters as the wrapped class.
- If
System.Dataclass implementation is concrete, perform a simple call to the wrapped instance. - If
System.Dataclass implementation returnsSqlCommandorSqlDataReaderin an async setting, create and return a newSqlCommandAsyncorSqlDataReaderAsyncwrapping the base output.