Daarto
Daarto copied to clipboard
Improve DB connection efficiency
At the moment each of the 8 classes inheriting from IdentityTable
create their own open connection to the DB at instantiation, all of which will only be closed when the scoped instance is disposed. This seems inefficient. I am a long way from an expert on the topic, but I wonder whether a more efficient method of doing this could be created by using any/all of:
- Have the scoped IDbConnectionFactory return a single instance rather than create a new connection every time. Have the
IDbConnectionFactory
- now really anIdbConnectionStore
implement IDisposable instead of theIdentityTables
, and rather than create have agetOrCreate
property. - Only access the connection in the
IdentityTable
instances when required, rather than at instantiation - Do not open the connection manually - as I understand if the connection is not open Dapper will open and close it automatically when one of the
execute
orquery
methods is called. It may however be more efficient to leave the connection open - I am unsure.