Skip to content

Commit 833c9f3

Browse files
Merge pull request #528 from johelvisguzman/issue527
Added interfaces for each repository context
2 parents d884b94 + c3cd2d0 commit 833c9f3

File tree

18 files changed

+284
-108
lines changed

18 files changed

+284
-108
lines changed

src/DotNetToolkit.Repository.AdoNet/Internal/DbHelper.cs renamed to src/DotNetToolkit.Repository.AdoNet/DbHelper.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
namespace DotNetToolkit.Repository.AdoNet.Internal
1+
namespace DotNetToolkit.Repository.AdoNet
22
{
33
using Configuration.Conventions;
44
using Configuration.Logging;
55
using Configuration.Logging.Internal;
66
using Extensions;
77
using Extensions.Internal;
8+
using Internal;
9+
using Queries;
810
using Queries.Internal;
911
using System;
1012
using System.Collections.Generic;
@@ -19,9 +21,9 @@ namespace DotNetToolkit.Repository.AdoNet.Internal
1921
using Utility;
2022

2123
/// <summary>
22-
/// Represents a database helper which contains various methods for retrieving nad manipulating data in a database.
24+
/// Represents a database helper which contains various methods for retrieving and manipulating data in a database.
2325
/// </summary>
24-
internal class DbHelper : IDisposable
26+
public class DbHelper : IDisposable
2527
{
2628
#region Fields
2729

@@ -30,7 +32,7 @@ internal class DbHelper : IDisposable
3032
private readonly string _connectionString;
3133
private DbConnection _connection;
3234
private readonly bool _ownsConnection;
33-
private readonly DataAccessProviderType _providerType;
35+
private readonly Internal.DataAccessProviderType _providerType;
3436
private readonly IRepositoryConventions _conventions;
3537

3638
#endregion
@@ -40,7 +42,7 @@ internal class DbHelper : IDisposable
4042
/// <summary>
4143
/// Gets the provider type.
4244
/// </summary>
43-
public DataAccessProviderType ProviderType { get { return _providerType; } }
45+
internal Internal.DataAccessProviderType ProviderType { get { return _providerType; } }
4446

4547
/// <summary>
4648
/// Gets the provider factory.
@@ -89,10 +91,10 @@ public DbHelper(IRepositoryConventions conventions, string nameOrConnectionStrin
8991
var css = GetConnectionStringSettings(nameOrConnectionString);
9092

9193
_conventions = conventions;
92-
_factory = DbProviderFactories.GetFactory(css.ProviderName);
94+
_factory = Internal.DbProviderFactories.GetFactory(css.ProviderName);
9395
_connectionString = css.ConnectionString;
9496
_ownsConnection = true;
95-
_providerType = DataAccessProvider.GetProviderType(css.ProviderName);
97+
_providerType = Internal.DataAccessProvider.GetProviderType(css.ProviderName);
9698
}
9799

98100
/// <summary>
@@ -108,10 +110,10 @@ public DbHelper(IRepositoryConventions conventions, string providerName, string
108110
Guard.NotEmpty(connectionString, nameof(connectionString));
109111

110112
_conventions = conventions;
111-
_factory = DbProviderFactories.GetFactory(providerName);
113+
_factory = Internal.DbProviderFactories.GetFactory(providerName);
112114
_connectionString = connectionString;
113115
_ownsConnection = true;
114-
_providerType = DataAccessProvider.GetProviderType(providerName);
116+
_providerType = Internal.DataAccessProvider.GetProviderType(providerName);
115117
}
116118

117119
/// <summary>
@@ -133,7 +135,7 @@ public DbHelper(IRepositoryConventions conventions, DbConnection existingConnect
133135

134136
var css = GetConnectionStringSettings(existingConnection.ConnectionString);
135137

136-
_providerType = DataAccessProvider.GetProviderType(css.ProviderName);
138+
_providerType = Internal.DataAccessProvider.GetProviderType(css.ProviderName);
137139
}
138140

139141
#endregion
@@ -429,7 +431,7 @@ public T ExecuteObject<T>(string cmdText, Dictionary<string, object> parameters,
429431
/// <param name="parameters">The command parameters.</param>
430432
/// <param name="projector">A function to project each entity into a new form.</param>
431433
/// <returns>A list which each entity has been projected into a new form.</returns>
432-
public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, CommandType cmdType, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector)
434+
public IPagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, CommandType cmdType, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector)
433435
{
434436
using (var reader = ExecuteReader(cmdText, cmdType, parameters))
435437
{
@@ -471,7 +473,7 @@ public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, CommandTy
471473
/// <param name="parameters">The command parameters.</param>
472474
/// <param name="projector">A function to project each entity into a new form.</param>
473475
/// <returns>A list which each entity has been projected into a new form.</returns>
474-
public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector)
476+
public IPagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector)
475477
{
476478
return ExecuteList<T>(cmdText, CommandType.Text, parameters, projector);
477479
}
@@ -483,7 +485,7 @@ public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, Dictionar
483485
/// <param name="cmdText">The command text.</param>
484486
/// <param name="parameters">The command parameters.</param>
485487
/// <returns>A list which each entity has been projected into a new form.</returns>
486-
public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, Dictionary<string, object> parameters) where T : class
488+
public IPagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, Dictionary<string, object> parameters) where T : class
487489
{
488490
var mapper = new Mapper<T>(_conventions);
489491

@@ -498,7 +500,7 @@ public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, Dictionar
498500
/// <param name="cmdType">The command type.</param>
499501
/// <param name="projector">A function to project each entity into a new form.</param>
500502
/// <returns>A list which each entity has been projected into a new form.</returns>
501-
public PagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, CommandType cmdType, Func<DbDataReader, IRepositoryConventions, T> projector)
503+
public IPagedQueryResult<IEnumerable<T>> ExecuteList<T>(string cmdText, CommandType cmdType, Func<DbDataReader, IRepositoryConventions, T> projector)
502504
{
503505
return ExecuteList<T>(cmdText, cmdType, null, projector);
504506
}
@@ -778,7 +780,7 @@ public Dictionary<TDictionaryKey, TElement> ExecuteDictionary<TDictionaryKey, TE
778780
/// <param name="projector">A function to project each entity into a new form.</param>
779781
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
780782
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a list which each entity has been projected into a new form.</returns>
781-
public async Task<PagedQueryResult<IEnumerable<T>>> ExecuteListAsync<T>(string cmdText, CommandType cmdType, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector, CancellationToken cancellationToken = new CancellationToken())
783+
public async Task<IPagedQueryResult<IEnumerable<T>>> ExecuteListAsync<T>(string cmdText, CommandType cmdType, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector, CancellationToken cancellationToken = new CancellationToken())
782784
{
783785
using (var reader = await ExecuteReaderAsync(cmdText, cmdType, parameters, cancellationToken))
784786
{
@@ -821,7 +823,7 @@ public Dictionary<TDictionaryKey, TElement> ExecuteDictionary<TDictionaryKey, TE
821823
/// <param name="projector">A function to project each entity into a new form.</param>
822824
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
823825
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a list which each entity has been projected into a new form.</returns>
824-
public Task<PagedQueryResult<IEnumerable<T>>> ExecuteListAsync<T>(string cmdText, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector, CancellationToken cancellationToken = new CancellationToken())
826+
public Task<IPagedQueryResult<IEnumerable<T>>> ExecuteListAsync<T>(string cmdText, Dictionary<string, object> parameters, Func<DbDataReader, IRepositoryConventions, T> projector, CancellationToken cancellationToken = new CancellationToken())
825827
{
826828
return ExecuteListAsync<T>(cmdText, CommandType.Text, parameters, projector, cancellationToken);
827829
}
@@ -834,7 +836,7 @@ public Dictionary<TDictionaryKey, TElement> ExecuteDictionary<TDictionaryKey, TE
834836
/// <param name="parameters">The command parameters.</param>
835837
/// <param name="cancellationToken">A <see cref="System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
836838
/// <returns>The <see cref="System.Threading.Tasks.Task" /> that represents the asynchronous operation, containing a list which each entity has been projected into a new form.</returns>
837-
public Task<PagedQueryResult<IEnumerable<T>>> ExecuteListAsync<T>(string cmdText, Dictionary<string, object> parameters, CancellationToken cancellationToken = new CancellationToken()) where T : class
839+
public Task<IPagedQueryResult<IEnumerable<T>>> ExecuteListAsync<T>(string cmdText, Dictionary<string, object> parameters, CancellationToken cancellationToken = new CancellationToken()) where T : class
838840
{
839841
var mapper = new Mapper<T>(_conventions);
840842

@@ -868,11 +870,17 @@ public Dictionary<TDictionaryKey, TElement> ExecuteDictionary<TDictionaryKey, TE
868870
}
869871
}
870872

873+
/// <summary>
874+
/// Maps the specified string sql data type value to <see cref="System.Type" />.
875+
/// </summary>
871876
public static Type MapToType(string sqlDataType)
872877
{
873878
return MapToType(MapToSqlDbType(sqlDataType));
874879
}
875880

881+
/// <summary>
882+
/// Maps the specified type to <see cref="System.Data.SqlDbType" />.
883+
/// </summary>
876884
public static SqlDbType MapToSqlDbType(Type type)
877885
{
878886
var typeMap = new Dictionary<Type, SqlDbType>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace DotNetToolkit.Repository.AdoNet
2+
{
3+
using Configuration;
4+
5+
/// <summary>
6+
/// Represents an ado.net repository context.
7+
/// </summary>
8+
/// <seealso cref="IRepositoryContextAsync" />
9+
public interface IAdoNetRepositoryContext : IRepositoryContextAsync
10+
{
11+
/// <summary>
12+
/// Gets the database helper which contains various methods for retrieving and manipulating data in a database.
13+
/// </summary>
14+
DbHelper DbHelper { get; }
15+
}
16+
}

src/DotNetToolkit.Repository.AdoNet/Internal/AdoNetRepositoryContext.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace DotNetToolkit.Repository.AdoNet.Internal
22
{
3-
using Configuration;
43
using Configuration.Conventions;
54
using Configuration.Logging;
65
using Configuration.Logging.Internal;
@@ -25,10 +24,10 @@
2524
using Utility;
2625

2726
/// <summary>
28-
/// Represents an internal ado.net repository context.
27+
/// An implementation of <see cref="IAdoNetRepositoryContext" />.
2928
/// </summary>
30-
/// <seealso cref="IRepositoryContextAsync" />
31-
internal class AdoNetRepositoryContext : IRepositoryContextAsync
29+
/// <seealso cref="IAdoNetRepositoryContext" />
30+
internal class AdoNetRepositoryContext : IAdoNetRepositoryContext
3231
{
3332
#region Fields
3433

@@ -130,6 +129,15 @@ public AdoNetRepositoryContext(DbConnection existingConnection, bool ensureDatab
130129

131130
#endregion
132131

132+
#region Implementation of IAdoNetRepositoryContext
133+
134+
/// <summary>
135+
/// Gets the database helper which contains various methods for retrieving and manipulating data in a database.
136+
/// </summary>
137+
public DbHelper DbHelper { get { return _dbHelper; } }
138+
139+
#endregion
140+
133141
#region Private Methods
134142

135143
private void PrepareEntitySetQuery(EntitySet entitySet, bool existInDb, out string sql, out Dictionary<string, object> parameters)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace DotNetToolkit.Repository.EntityFramework
2+
{
3+
using Configuration;
4+
using System.Data.Entity;
5+
6+
/// <summary>
7+
/// Represents a entity framework repository context.
8+
/// </summary>
9+
/// <seealso cref="IRepositoryContextAsync" />
10+
public interface IEfRepositoryContext : IRepositoryContextAsync
11+
{
12+
/// <summary>
13+
/// Gets the underlying context.
14+
/// </summary>
15+
DbContext UnderlyingContext { get; }
16+
}
17+
}

src/DotNetToolkit.Repository.EntityFramework/Internal/EfRepositoryContext.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
using Utility;
1818

1919
/// <summary>
20-
/// Represents an internal entity framework repository context.
20+
/// An implementation of <see cref="IEfRepositoryContext" />.
2121
/// </summary>
22-
/// <seealso cref="IRepositoryContextAsync" />
23-
internal class EfRepositoryContext : LinqRepositoryContextBaseAsync
22+
/// <seealso cref="IEfRepositoryContext" />
23+
internal class EfRepositoryContext : LinqRepositoryContextBaseAsync, IEfRepositoryContext
2424
{
2525
#region Fields
2626

@@ -44,6 +44,15 @@ public EfRepositoryContext(DbContext context)
4444

4545
#endregion
4646

47+
#region Implementation of IEfRepositoryContext
48+
49+
/// <summary>
50+
/// Gets the underlying context.
51+
/// </summary>
52+
public DbContext UnderlyingContext { get { return _context; } }
53+
54+
#endregion
55+
4756
#region Implementation of IRepositoryContext
4857

4958
/// <summary>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace DotNetToolkit.Repository.EntityFrameworkCore
2+
{
3+
using Configuration;
4+
using Microsoft.EntityFrameworkCore;
5+
6+
/// <summary>
7+
/// Represents a entity framework repository context.
8+
/// </summary>
9+
/// <seealso cref="IRepositoryContextAsync" />
10+
public interface IEfCoreRepositoryContext : IRepositoryContextAsync
11+
{
12+
/// <summary>
13+
/// Gets the underlying context.
14+
/// </summary>
15+
DbContext UnderlyingContext { get; }
16+
}
17+
}

src/DotNetToolkit.Repository.EntityFrameworkCore/Internal/EfCoreRepositoryContext.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
using Utility;
1818

1919
/// <summary>
20-
/// Represents an internal entity framework core repository context.
20+
/// An implementation of <see cref="IEfCoreRepositoryContext" />.
2121
/// </summary>
22-
/// <seealso cref="IRepositoryContextAsync" />
23-
internal class EfCoreRepositoryContext : LinqRepositoryContextBaseAsync
22+
/// <seealso cref="IEfCoreRepositoryContext" />
23+
internal class EfCoreRepositoryContext : LinqRepositoryContextBaseAsync, IEfCoreRepositoryContext
2424
{
2525
#region Fields
2626

@@ -44,6 +44,15 @@ public EfCoreRepositoryContext(DbContext context)
4444

4545
#endregion
4646

47+
#region Implementation of IEfCoreRepositoryContext
48+
49+
/// <summary>
50+
/// Gets the underlying context.
51+
/// </summary>
52+
public DbContext UnderlyingContext { get { return _context; } }
53+
54+
#endregion
55+
4756
#region Implementation of IRepositoryContext
4857

4958
/// <summary>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace DotNetToolkit.Repository.InMemory
2+
{
3+
using Configuration;
4+
5+
/// <summary>
6+
/// Represents an internal repository context for in-memory operations (for testing purposes).
7+
/// </summary>
8+
/// <seealso cref="IRepositoryContext" />
9+
public interface IInMemoryRepositoryContext : IRepositoryContext
10+
{
11+
/// <summary>
12+
/// Gets or sets the name of the database.
13+
/// </summary>
14+
string DatabaseName { get; set; }
15+
16+
/// <summary>
17+
/// Ensures the in-memory store is completely deleted.
18+
/// </summary>
19+
void EnsureDeleted();
20+
}
21+
}

0 commit comments

Comments
 (0)