Skip to content

Commit 2bb2361

Browse files
Merge pull request #99 from johelvisguzman/issue97
Added changes to support the ability to intercept certain activities in the repository as well errors/exceptions
2 parents d4ba795 + f52dbec commit 2bb2361

31 files changed

+1162
-460
lines changed

src/DotNetToolkit.Repository.AdoNet/AdoNetRepository.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DotNetToolkit.Repository.AdoNet
22
{
3-
using Logging;
3+
using Interceptors;
4+
using System.Collections.Generic;
45

56
/// <summary>
67
/// Represents a repository for entity framework.
@@ -26,16 +27,16 @@ public AdoNetRepository(string providerName, string connectionString) : base(pro
2627
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
2728
/// </summary>
2829
/// <param name="connectionString">The connection string.</param>
29-
/// <param name="logger">The logger.</param>
30-
public AdoNetRepository(string connectionString, ILogger logger) : base(connectionString, logger) { }
30+
/// <param name="interceptors">The interceptors.</param>
31+
public AdoNetRepository(string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(connectionString, interceptors) { }
3132

3233
/// <summary>
3334
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity, TKey}" /> class.
3435
/// </summary>
3536
/// <param name="providerName">The name of the provider.</param>
3637
/// <param name="connectionString">The connection string.</param>
37-
/// <param name="logger">The logger.</param>
38-
public AdoNetRepository(string providerName, string connectionString, ILogger logger) : base(providerName, connectionString, logger) { }
38+
/// <param name="interceptors">The interceptors.</param>
39+
public AdoNetRepository(string providerName, string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(providerName, connectionString, interceptors) { }
3940

4041
#endregion
4142
}
@@ -64,16 +65,16 @@ public AdoNetRepository(string providerName, string connectionString) : base(pro
6465
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity}" /> class.
6566
/// </summary>
6667
/// <param name="connectionString">The connection string.</param>
67-
/// <param name="logger">The logger.</param>
68-
public AdoNetRepository(string connectionString, ILogger logger) : base(connectionString, logger) { }
68+
/// <param name="interceptors">The interceptors.</param>
69+
public AdoNetRepository(string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(connectionString, interceptors) { }
6970

7071
/// <summary>
7172
/// Initializes a new instance of the <see cref="AdoNetRepository{TEntity}" /> class.
7273
/// </summary>
7374
/// <param name="providerName">The name of the provider.</param>
7475
/// <param name="connectionString">The connection string.</param>
75-
/// <param name="logger">The logger.</param>
76-
public AdoNetRepository(string providerName, string connectionString, ILogger logger) : base(providerName, connectionString, logger) { }
76+
/// <param name="interceptors">The interceptors.</param>
77+
public AdoNetRepository(string providerName, string connectionString, IEnumerable<IRepositoryInterceptor> interceptors) : base(providerName, connectionString, interceptors) { }
7778

7879
#endregion
7980
}

src/DotNetToolkit.Repository.AdoNet/AdoNetRepositoryBase.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
{
33
using FetchStrategies;
44
using Helpers;
5+
using Interceptors;
56
using Internal;
6-
using Logging;
77
using Properties;
88
using Queries;
99
using Specifications;
@@ -71,8 +71,8 @@ public abstract class AdoNetRepositoryBase<TEntity, TKey> : RepositoryBaseAsync<
7171
/// Initializes a new instance of the <see cref="AdoNetRepositoryBase{TEntity, TKey}"/> class.
7272
/// </summary>
7373
/// <param name="connectionString">The connection string.</param>
74-
/// <param name="logger">The logger.</param>
75-
protected AdoNetRepositoryBase(string connectionString, ILogger logger = null) : base(logger)
74+
/// <param name="interceptors">The interceptors.</param>
75+
protected AdoNetRepositoryBase(string connectionString, IEnumerable<IRepositoryInterceptor> interceptors = null) : base(interceptors)
7676
{
7777
if (string.IsNullOrEmpty(connectionString))
7878
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmptyString, nameof(connectionString));
@@ -92,8 +92,8 @@ protected AdoNetRepositoryBase(string connectionString, ILogger logger = null) :
9292
/// </summary>
9393
/// <param name="providerName">The name of the provider.</param>
9494
/// <param name="connectionString">The connection string.</param>
95-
/// <param name="logger">The logger.</param>
96-
protected AdoNetRepositoryBase(string providerName, string connectionString, ILogger logger = null) : base(logger)
95+
/// <param name="interceptors">The interceptors.</param>
96+
protected AdoNetRepositoryBase(string providerName, string connectionString, IEnumerable<IRepositoryInterceptor> interceptors = null) : base(interceptors)
9797
{
9898
if (string.IsNullOrEmpty(providerName))
9999
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmptyString, nameof(providerName));

src/DotNetToolkit.Repository.AdoNet/AdoNetRepositoryFactory.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace DotNetToolkit.Repository.AdoNet
22
{
3-
using Logging;
3+
using Interceptors;
44
using System;
55
using System.Collections.Generic;
66

@@ -13,7 +13,7 @@ public class AdoNetRepositoryFactory : IRepositoryFactory
1313

1414
private const string ProviderNameKey = "providerName";
1515
private const string ConnectionStringKey = "connectionString";
16-
private const string LoggerKey = "logger";
16+
private const string InterceptorsKey = "interceptors";
1717

1818
private readonly Dictionary<string, object> _options;
1919

@@ -44,7 +44,7 @@ public AdoNetRepositoryFactory(Dictionary<string, object> options)
4444

4545
#region Private Methods
4646

47-
private static void GetOptions(Dictionary<string, object> options, out string providerName, out string connectionString, out ILogger logger)
47+
private static void GetOptions(Dictionary<string, object> options, out string providerName, out string connectionString, out IEnumerable<IRepositoryInterceptor> interceptors)
4848
{
4949
if (options == null)
5050
throw new ArgumentNullException(nameof(options));
@@ -55,15 +55,15 @@ private static void GetOptions(Dictionary<string, object> options, out string pr
5555
object value = null;
5656
providerName = null;
5757
connectionString = null;
58-
logger = null;
58+
interceptors = null;
5959

6060
if (options.ContainsKey(ProviderNameKey))
6161
{
6262
value = options[ProviderNameKey];
6363
providerName = value as string;
6464

6565
if (value != null && providerName == null)
66-
throw new ArgumentException($"The option value for the specified '{ProviderNameKey}' key must be a valid '{typeof(string).Name}' type.");
66+
throw new ArgumentException($"The option value for the specified '{ProviderNameKey}' key must be a valid 'System.String' type.");
6767
}
6868

6969
if (options.ContainsKey(ConnectionStringKey))
@@ -72,20 +72,20 @@ private static void GetOptions(Dictionary<string, object> options, out string pr
7272
connectionString = value as string;
7373

7474
if (value != null && connectionString == null)
75-
throw new ArgumentException($"The option value for the specified '{ConnectionStringKey}' key must be a valid '{typeof(string).Name}' type.");
75+
throw new ArgumentException($"The option value for the specified '{ConnectionStringKey}' key must be a valid 'System.String' type.");
7676
}
7777
else
7878
{
7979
throw new InvalidOperationException($"The '{ConnectionStringKey}' option is missing from the options dictionary.");
8080
}
8181

82-
if (options.ContainsKey(LoggerKey))
82+
if (options.ContainsKey(InterceptorsKey))
8383
{
84-
value = options[LoggerKey];
85-
logger = value as ILogger;
84+
value = options[InterceptorsKey];
85+
interceptors = value as IEnumerable<IRepositoryInterceptor>;
8686

87-
if (value != null && logger == null)
88-
throw new ArgumentException($"The option value for the specified '{LoggerKey}' key must be a valid '{typeof(ILogger).Name}' type.");
87+
if (value != null && interceptors == null)
88+
throw new ArgumentException($"The option value for the specified '{InterceptorsKey}' key must be a valid 'System.Collections.Generic.IEnumerable<DotNetToolkit.Repository.IRepositoryInterceptor>' type.");
8989
}
9090
}
9191

@@ -128,11 +128,11 @@ public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
128128
/// <returns>The new repository.</returns>
129129
public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options) where TEntity : class
130130
{
131-
GetOptions(options, out string providerName, out string connectionString, out ILogger logger);
131+
GetOptions(options, out string providerName, out string connectionString, out IEnumerable<IRepositoryInterceptor> interceptors);
132132

133133
return string.IsNullOrEmpty(providerName)
134-
? new AdoNetRepository<TEntity>(connectionString, logger)
135-
: new AdoNetRepository<TEntity>(providerName, connectionString, logger);
134+
? new AdoNetRepository<TEntity>(connectionString, interceptors)
135+
: new AdoNetRepository<TEntity>(providerName, connectionString, interceptors);
136136
}
137137

138138
/// <summary>
@@ -144,11 +144,11 @@ public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options)
144144
/// <returns>The new repository.</returns>
145145
public IRepository<TEntity, TKey> Create<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
146146
{
147-
GetOptions(options, out string providerName, out string connectionString, out ILogger logger);
147+
GetOptions(options, out string providerName, out string connectionString, out IEnumerable<IRepositoryInterceptor> interceptors);
148148

149149
return string.IsNullOrEmpty(providerName)
150-
? new AdoNetRepository<TEntity, TKey>(connectionString, logger)
151-
: new AdoNetRepository<TEntity, TKey>(providerName, connectionString, logger);
150+
? new AdoNetRepository<TEntity, TKey>(connectionString, interceptors)
151+
: new AdoNetRepository<TEntity, TKey>(providerName, connectionString, interceptors);
152152
}
153153

154154
#endregion

src/DotNetToolkit.Repository.Csv/CsvRepository.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DotNetToolkit.Repository.Csv
22
{
3-
using Logging;
3+
using Interceptors;
4+
using System.Collections.Generic;
45

56
/// <summary>
67
/// Represents a repository for storing entities as an csv formatted file.
@@ -21,8 +22,8 @@ public CsvRepository(string filePath) : base(filePath)
2122
/// Initializes a new instance of the <see cref="CsvRepository{TEntity, TKey}"/> class.
2223
/// </summary>
2324
/// <param name="filePath">The file path.</param>
24-
/// <param name="logger">The logger.</param>
25-
public CsvRepository(string filePath, ILogger logger) : base(filePath, logger)
25+
/// <param name="interceptors">The interceptors.</param>
26+
public CsvRepository(string filePath, IEnumerable<IRepositoryInterceptor> interceptors) : base(filePath, interceptors)
2627
{
2728
}
2829

@@ -48,8 +49,8 @@ public CsvRepository(string filePath) : base(filePath)
4849
/// Initializes a new instance of the <see cref="CsvRepository{TEntity}"/> class.
4950
/// </summary>
5051
/// <param name="filePath">The file path.</param>
51-
/// <param name="logger">The logger.</param>
52-
public CsvRepository(string filePath, ILogger logger) : base(filePath, logger)
52+
/// <param name="interceptors">The interceptors.</param>
53+
public CsvRepository(string filePath, IEnumerable<IRepositoryInterceptor> interceptors) : base(filePath, interceptors)
5354
{
5455
}
5556

src/DotNetToolkit.Repository.Csv/CsvRepositoryBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
using CsvHelper;
44
using InMemory;
5-
using Logging;
5+
using Interceptors;
66
using System.Collections.Generic;
77
using System.IO;
88

@@ -25,8 +25,8 @@ protected CsvRepositoryBase(string filePath) : base(filePath)
2525
/// Initializes a new instance of the <see cref="CsvRepositoryBase{TEntity, TKey}"/> class.
2626
/// </summary>
2727
/// <param name="filePath">The file path.</param>
28-
/// <param name="logger">The logger.</param>
29-
protected CsvRepositoryBase(string filePath, ILogger logger) : base(filePath, logger)
28+
/// <param name="interceptors">The interceptors.</param>
29+
protected CsvRepositoryBase(string filePath, IEnumerable<IRepositoryInterceptor> interceptors) : base(filePath, interceptors)
3030
{
3131
}
3232

src/DotNetToolkit.Repository.Csv/CsvRepositoryFactory.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace DotNetToolkit.Repository.Csv
22
{
3-
using Logging;
3+
using Interceptors;
44
using System;
55
using System.Collections.Generic;
66

@@ -12,7 +12,7 @@ public class CsvRepositoryFactory : IRepositoryFactory
1212
#region Fields
1313

1414
private const string FilePathOptionKey = "path";
15-
private const string LoggerKey = "logger";
15+
private const string InterceptorsKey = "interceptors";
1616

1717
private readonly Dictionary<string, object> _options;
1818

@@ -43,7 +43,7 @@ public CsvRepositoryFactory(Dictionary<string, object> options)
4343

4444
#region Private Methods
4545

46-
private static void GetOptions(Dictionary<string, object> options, out string path, out ILogger logger)
46+
private static void GetOptions(Dictionary<string, object> options, out string path, out IEnumerable<IRepositoryInterceptor> interceptors)
4747
{
4848
if (options == null)
4949
throw new ArgumentNullException(nameof(options));
@@ -53,28 +53,28 @@ private static void GetOptions(Dictionary<string, object> options, out string pa
5353

5454
object value = null;
5555
path = null;
56-
logger = null;
56+
interceptors = null;
5757

5858
if (options.ContainsKey(FilePathOptionKey))
5959
{
6060
value = options[FilePathOptionKey];
6161
path = value as string;
6262

6363
if (value != null && path == null)
64-
throw new ArgumentException($"The option value for the specified '{FilePathOptionKey}' key must be a valid '{typeof(string).Name}' type.");
64+
throw new ArgumentException($"The option value for the specified '{FilePathOptionKey}' key must be a valid 'System.String' type.");
6565
}
6666
else
6767
{
6868
throw new InvalidOperationException($"The '{FilePathOptionKey}' option is missing from the options dictionary.");
6969
}
7070

71-
if (options.ContainsKey(LoggerKey))
71+
if (options.ContainsKey(InterceptorsKey))
7272
{
73-
value = options[LoggerKey];
74-
logger = value as ILogger;
73+
value = options[InterceptorsKey];
74+
interceptors = value as IEnumerable<IRepositoryInterceptor>;
7575

76-
if (value != null && logger == null)
77-
throw new ArgumentException($"The option value for the specified '{LoggerKey}' key must be a valid '{typeof(ILogger).Name}' type.");
76+
if (value != null && interceptors == null)
77+
throw new ArgumentException($"The option value for the specified '{InterceptorsKey}' key must be a valid 'System.Collections.Generic.IEnumerable<DotNetToolkit.Repository.IRepositoryInterceptor>' type.");
7878
}
7979
}
8080

@@ -117,9 +117,9 @@ public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
117117
/// <returns>The new repository.</returns>
118118
public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options) where TEntity : class
119119
{
120-
GetOptions(options, out string path, out ILogger logger);
120+
GetOptions(options, out string path, out IEnumerable<IRepositoryInterceptor> interceptors);
121121

122-
return new CsvRepository<TEntity>(path, logger);
122+
return new CsvRepository<TEntity>(path, interceptors);
123123
}
124124

125125
/// <summary>
@@ -131,9 +131,9 @@ public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options)
131131
/// <returns>The new repository.</returns>
132132
public IRepository<TEntity, TKey> Create<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
133133
{
134-
GetOptions(options, out string path, out ILogger logger);
134+
GetOptions(options, out string path, out IEnumerable<IRepositoryInterceptor> interceptors);
135135

136-
return new CsvRepository<TEntity, TKey>(path, logger);
136+
return new CsvRepository<TEntity, TKey>(path, interceptors);
137137
}
138138

139139
#endregion

src/DotNetToolkit.Repository.EntityFramework/EfRepository.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace DotNetToolkit.Repository.EntityFramework
22
{
3-
using Logging;
3+
using Interceptors;
4+
using System.Collections.Generic;
45
using System.Data.Entity;
56

67
/// <summary>
@@ -20,8 +21,8 @@ public EfRepository(DbContext context) : base(context) { }
2021
/// Initializes a new instance of the <see cref="EfRepository{TEntity, TKey}" /> class.
2122
/// </summary>
2223
/// <param name="context">The database context.</param>
23-
/// <param name="logger">The logger.</param>
24-
public EfRepository(DbContext context, ILogger logger) : base(context, logger) { }
24+
/// <param name="interceptors">The interceptors.</param>
25+
public EfRepository(DbContext context, IEnumerable<IRepositoryInterceptor> interceptors) : base(context, interceptors) { }
2526

2627
#endregion
2728
}
@@ -43,8 +44,8 @@ public EfRepository(DbContext context) : base(context) { }
4344
/// Initializes a new instance of the <see cref="EfRepository{TEntity}" /> class.
4445
/// </summary>
4546
/// <param name="context">The database context.</param>
46-
/// <param name="logger">The logger.</param>
47-
public EfRepository(DbContext context, ILogger logger) : base(context, logger) { }
47+
/// <param name="interceptors">The interceptors.</param>
48+
public EfRepository(DbContext context, IEnumerable<IRepositoryInterceptor> interceptors) : base(context, interceptors) { }
4849

4950
#endregion
5051
}

src/DotNetToolkit.Repository.EntityFramework/EfRepositoryBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace DotNetToolkit.Repository.EntityFramework
22
{
33
using FetchStrategies;
4-
using Logging;
4+
using Interceptors;
55
using Queries;
66
using Specifications;
77
using System;
@@ -51,8 +51,8 @@ protected EfRepositoryBase(DbContext context) : this (context, null)
5151
/// Initializes a new instance of the <see cref="EfRepositoryBase{TEntity, TKey}" /> class.
5252
/// </summary>
5353
/// <param name="context">The database context.</param>
54-
/// <param name="logger">The logger.</param>
55-
protected EfRepositoryBase(DbContext context, ILogger logger) : base(logger)
54+
/// <param name="interceptors">The interceptors.</param>
55+
protected EfRepositoryBase(DbContext context, IEnumerable<IRepositoryInterceptor> interceptors) : base(interceptors)
5656
{
5757
if (context == null)
5858
throw new ArgumentNullException(nameof(context));

0 commit comments

Comments
 (0)