@@ -10,85 +10,76 @@ namespace Dibix.Dapper
1010{
1111 public class DapperDatabaseAccessor : DatabaseAccessor , IDatabaseAccessor , IDisposable
1212 {
13- #region Fields
14- private readonly IDbTransaction _defaultTransaction ;
15- private readonly int ? _defaultCommandTimeout ;
16- private readonly Action _onDispose ;
17- #endregion
18-
1913 #region Constructor
20- public DapperDatabaseAccessor ( DbConnection connection , IDbTransaction defaultTransaction = null , int ? defaultCommandTimeout = null , Action onDispose = null ) : base ( connection )
14+ public DapperDatabaseAccessor ( DbConnection connection , DatabaseAccessorOptions options ) : base ( connection , options )
2115 {
22- _defaultTransaction = defaultTransaction ;
23- _defaultCommandTimeout = defaultCommandTimeout ;
24- _onDispose = onDispose ;
2516 ConfigureDapper ( ) ;
2617 }
2718 #endregion
2819
2920 #region Overrides
3021 protected override int Execute ( string commandText , CommandType commandType , ParametersVisitor parameters , int ? commandTimeout )
3122 {
32- return base . Connection . Execute ( commandText , CollectParameters ( parameters ) , _defaultTransaction , commandTimeout ?? _defaultCommandTimeout , commandType ) ;
23+ return base . Connection . Execute ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , commandTimeout ?? Options . DefaultCommandTimeout , commandType ) ;
3324 }
3425
3526 protected override Task < int > ExecuteAsync ( string commandText , CommandType commandType , ParametersVisitor parameters , int ? commandTimeout , CancellationToken cancellationToken )
3627 {
37- CommandDefinition command = new CommandDefinition ( commandText , CollectParameters ( parameters ) , _defaultTransaction , commandTimeout ?? _defaultCommandTimeout , commandType , cancellationToken : cancellationToken ) ;
28+ CommandDefinition command = new CommandDefinition ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , commandTimeout ?? Options . DefaultCommandTimeout , commandType , cancellationToken : cancellationToken ) ;
3829 return base . Connection . ExecuteAsync ( command ) ;
3930 }
4031
4132 protected override IEnumerable < T > QueryMany < T > ( string commandText , CommandType commandType , ParametersVisitor parameters )
4233 {
4334 DecoratedTypeMap . Adapt < T > ( ) ;
44- return base . Connection . Query < T > ( commandText , CollectParameters ( parameters ) , _defaultTransaction , commandTimeout : _defaultCommandTimeout , commandType : commandType ) ;
35+ return base . Connection . Query < T > ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , commandTimeout : Options . DefaultCommandTimeout , commandType : commandType ) ;
4536 }
4637
4738 protected override IEnumerable < T > QueryMany < T > ( string commandText , CommandType commandType , ParametersVisitor parameters , bool buffered )
4839 {
4940 DecoratedTypeMap . Adapt < T > ( ) ;
50- return base . Connection . Query < T > ( commandText , CollectParameters ( parameters ) , _defaultTransaction , buffered , _defaultCommandTimeout , commandType ) ;
41+ return base . Connection . Query < T > ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , buffered , Options . DefaultCommandTimeout , commandType ) ;
5142 }
5243
5344 protected override Task < IEnumerable < T > > QueryManyAsync < T > ( string commandText , CommandType commandType , ParametersVisitor parameters , bool buffered , CancellationToken cancellationToken )
5445 {
5546 DecoratedTypeMap . Adapt < T > ( ) ;
5647 CommandFlags flags = buffered ? CommandFlags . Buffered : CommandFlags . None ;
57- CommandDefinition command = new CommandDefinition ( commandText , CollectParameters ( parameters ) , _defaultTransaction , _defaultCommandTimeout , commandType , flags , cancellationToken ) ;
48+ CommandDefinition command = new CommandDefinition ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , Options . DefaultCommandTimeout , commandType , flags , cancellationToken ) ;
5849 return base . Connection . QueryAsync < T > ( command ) ;
5950 }
6051
6152 protected override IEnumerable < TReturn > QueryMany < TReturn > ( string commandText , CommandType commandType , ParametersVisitor parameters , Type [ ] types , Func < object [ ] , TReturn > map , string splitOn , bool buffered )
6253 {
6354 DecoratedTypeMap . Adapt ( types ) ;
64- return base . Connection . Query ( commandText , types , map , CollectParameters ( parameters ) , _defaultTransaction , splitOn : splitOn , commandTimeout : _defaultCommandTimeout , commandType : commandType , buffered : buffered ) ;
55+ return base . Connection . Query ( commandText , types , map , CollectParameters ( parameters ) , Options . DefaultTransaction , splitOn : splitOn , commandTimeout : Options . DefaultCommandTimeout , commandType : commandType , buffered : buffered ) ;
6556 }
6657
6758 protected override Task < IEnumerable < TReturn > > QueryManyAsync < TReturn > ( string commandText , CommandType commandType , ParametersVisitor parameters , Type [ ] types , Func < object [ ] , TReturn > map , string splitOn , bool buffered , CancellationToken cancellationToken )
6859 {
6960 DecoratedTypeMap . Adapt ( types ) ;
7061 // NOTE: Apparently there is no overload in Dapper that either accepts CancellationToken or CommandDefinition and Type[]
71- return Connection . QueryAsync ( commandText , types , map , CollectParameters ( parameters ) , _defaultTransaction , splitOn : splitOn , commandTimeout : _defaultCommandTimeout , commandType : commandType , buffered : buffered ) ;
62+ return Connection . QueryAsync ( commandText , types , map , CollectParameters ( parameters ) , Options . DefaultTransaction , splitOn : splitOn , commandTimeout : Options . DefaultCommandTimeout , commandType : commandType , buffered : buffered ) ;
7263 }
7364
7465 protected override IMultipleResultReader QueryMultiple ( string commandText , CommandType commandType , ParametersVisitor parameters )
7566 {
76- SqlMapper . GridReader reader = base . Connection . QueryMultiple ( commandText , CollectParameters ( parameters ) , _defaultTransaction , commandTimeout : _defaultCommandTimeout , commandType : commandType ) ;
77- return new DapperGridResultReader ( reader , commandText , commandType , parameters , DbProviderAdapter ) ;
67+ SqlMapper . GridReader reader = base . Connection . QueryMultiple ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , commandTimeout : Options . DefaultCommandTimeout , commandType : commandType ) ;
68+ return new DapperGridResultReader ( reader , commandText , commandType , parameters , DbProviderAdapter , Options ) ;
7869 }
7970
8071 protected override async Task < IMultipleResultReader > QueryMultipleAsync ( string commandText , CommandType commandType , ParametersVisitor parameters , CancellationToken cancellationToken )
8172 {
82- SqlMapper . GridReader reader = await base . Connection . QueryMultipleAsync ( new CommandDefinition ( commandText , CollectParameters ( parameters ) , _defaultTransaction , _defaultCommandTimeout , commandType , cancellationToken : cancellationToken ) ) . ConfigureAwait ( false ) ;
83- return new DapperGridResultReader ( reader , commandText , commandType , parameters , DbProviderAdapter ) ;
73+ SqlMapper . GridReader reader = await base . Connection . QueryMultipleAsync ( new CommandDefinition ( commandText , CollectParameters ( parameters ) , Options . DefaultTransaction , Options . DefaultCommandTimeout , commandType , cancellationToken : cancellationToken ) ) . ConfigureAwait ( false ) ;
74+ return new DapperGridResultReader ( reader , commandText , commandType , parameters , DbProviderAdapter , Options ) ;
8475 }
8576
8677 protected override IEnumerable < TReturn > Parse < TReturn > ( IDataReader reader ) => reader . Parse < TReturn > ( ) ;
8778
8879 protected override void DisposeConnection ( )
8980 {
90- if ( _onDispose != null )
91- _onDispose . Invoke ( ) ;
81+ if ( Options . OnDispose != null )
82+ Options . OnDispose . Invoke ( ) ;
9283 else
9384 base . DisposeConnection ( ) ;
9485 }
0 commit comments