giorgos07/Daarto

Improve DB connection efficiency

Opened this issue · 0 comments

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:

  1. Have the scoped IDbConnectionFactory return a single instance rather than create a new connection every time. Have the IDbConnectionFactory - now really an IdbConnectionStore implement IDisposable instead of the IdentityTables, and rather than create have a getOrCreate property.
  2. Only access the connection in the IdentityTable instances when required, rather than at instantiation
  3. 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 or query methods is called. It may however be more efficient to leave the connection open - I am unsure.