@@ -9,19 +9,25 @@ namespace Beacon.Sdk.Core.Infrastructure.Repositories
99 public abstract class BaseLiteDbRepository < T >
1010 {
1111 private readonly ILogger < BaseLiteDbRepository < T > > _logger ;
12- private readonly ILiteDatabase _db ;
12+ private readonly ILiteDbConnectionPool _connectionPool ;
13+ private readonly RepositorySettings _settings ;
1314
14- protected BaseLiteDbRepository ( ILiteDbConnectionPool connectionPool , ILogger < BaseLiteDbRepository < T > > logger , RepositorySettings settings )
15+ protected BaseLiteDbRepository (
16+ ILiteDbConnectionPool connectionPool ,
17+ ILogger < BaseLiteDbRepository < T > > logger ,
18+ RepositorySettings settings )
1519 {
20+ _connectionPool = connectionPool ?? throw new ArgumentNullException ( nameof ( connectionPool ) ) ;
21+ _settings = settings ?? throw new ArgumentNullException ( nameof ( settings ) ) ;
1622 _logger = logger ;
17- _db = connectionPool . OpenConnection ( new ConnectionString ( settings . ConnectionString ) ) ;
1823 }
1924
2025 protected Task InConnectionAction ( string collectionName , Action < ILiteCollection < T > > func )
2126 {
2227 try
2328 {
24- ILiteCollection < T > col = _db . GetCollection < T > ( collectionName ) ;
29+ var db = _connectionPool . OpenConnection ( new ConnectionString ( _settings . ConnectionString ) ) ;
30+ var col = db . GetCollection < T > ( collectionName ) ;
2531 func ( col ) ;
2632 }
2733 catch ( Exception e )
@@ -36,7 +42,8 @@ protected Task<T> InConnection(string collectionName, Func<ILiteCollection<T>, T
3642 {
3743 try
3844 {
39- ILiteCollection < T > col = _db . GetCollection < T > ( collectionName ) ;
45+ var db = _connectionPool . OpenConnection ( new ConnectionString ( _settings . ConnectionString ) ) ;
46+ var col = db . GetCollection < T > ( collectionName ) ;
4047 return func ( col ) ;
4148 }
4249 catch ( Exception e )
@@ -50,8 +57,9 @@ protected Task InConnection(string collectionName, Action<ILiteDatabase, ILiteCo
5057 {
5158 try
5259 {
53- ILiteCollection < T > col = _db . GetCollection < T > ( collectionName ) ;
54- func ( _db , col ) ;
60+ var db = _connectionPool . OpenConnection ( new ConnectionString ( _settings . ConnectionString ) ) ;
61+ var col = db . GetCollection < T > ( collectionName ) ;
62+ func ( db , col ) ;
5563 }
5664 catch ( Exception e )
5765 {
@@ -65,7 +73,8 @@ protected Task InConnection(string collectionName, Action<ILiteDatabase, ILiteCo
6573 {
6674 try
6775 {
68- ILiteCollection < T > col = _db . GetCollection < T > ( collectionName ) ;
76+ var db = _connectionPool . OpenConnection ( new ConnectionString ( _settings . ConnectionString ) ) ;
77+ var col = db . GetCollection < T > ( collectionName ) ;
6978 return func ( col ) ;
7079
7180 }
@@ -81,7 +90,8 @@ protected Task InConnection(string collectionName, Action<ILiteDatabase, ILiteCo
8190 {
8291 try
8392 {
84- ILiteCollection < T > col = _db . GetCollection < T > ( collectionName ) ;
93+ var db = _connectionPool . OpenConnection ( new ConnectionString ( _settings . ConnectionString ) ) ;
94+ var col = db . GetCollection < T > ( collectionName ) ;
8595 return func ( col ) ;
8696
8797 }
@@ -97,7 +107,8 @@ protected Task<List<T>> InConnection(string collectionName, Func<ILiteCollection
97107 {
98108 try
99109 {
100- ILiteCollection < T > col = _db . GetCollection < T > ( collectionName ) ;
110+ var db = _connectionPool . OpenConnection ( new ConnectionString ( _settings . ConnectionString ) ) ;
111+ var col = db . GetCollection < T > ( collectionName ) ;
101112 return func ( col ) ;
102113 }
103114 catch ( Exception e )
0 commit comments