Skip to content

Commit 3c1e591

Browse files
Merge pull request #103 from johelvisguzman/issue98
Made changes to support an asynchronous repository factory
2 parents f9917ca + 9e44dc9 commit 3c1e591

File tree

9 files changed

+234
-40
lines changed

9 files changed

+234
-40
lines changed

src/DotNetToolkit.Repository.AdoNet/AdoNetRepositoryFactory.cs

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
namespace DotNetToolkit.Repository.AdoNet
22
{
3+
using Factories;
34
using Interceptors;
45
using System;
56
using System.Collections.Generic;
67

78
/// <summary>
8-
/// An implementation of <see cref="IRepositoryFactory" />.
9+
/// An implementation of <see cref="IRepositoryFactoryAsync" />.
910
/// </summary>
10-
public class AdoNetRepositoryFactory : IRepositoryFactory
11+
public class AdoNetRepositoryFactory : IRepositoryFactoryAsync
1112
{
1213
#region Fields
1314

@@ -100,10 +101,7 @@ private static void GetOptions(Dictionary<string, object> options, out string pr
100101
/// <returns>The new repository.</returns>
101102
public IRepository<TEntity> Create<TEntity>() where TEntity : class
102103
{
103-
if (_options == null)
104-
throw new InvalidOperationException("No options have been provided.");
105-
106-
return Create<TEntity>(_options);
104+
return CreateAsync<TEntity>();
107105
}
108106

109107
/// <summary>
@@ -114,10 +112,7 @@ public IRepository<TEntity> Create<TEntity>() where TEntity : class
114112
/// <returns>The new repository.</returns>
115113
public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
116114
{
117-
if (_options == null)
118-
throw new InvalidOperationException("No options have been provided.");
119-
120-
return Create<TEntity, TKey>(_options);
115+
return CreateAsync<TEntity, TKey>();
121116
}
122117

123118
/// <summary>
@@ -127,6 +122,60 @@ public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
127122
/// <param name="options">The options.</param>
128123
/// <returns>The new repository.</returns>
129124
public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options) where TEntity : class
125+
{
126+
return CreateAsync<TEntity>(options);
127+
}
128+
129+
/// <summary>
130+
/// Creates a new repository for the specified entity and primary key type.
131+
/// </summary>
132+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
133+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
134+
/// <param name="options">The options.</param>
135+
/// <returns>The new repository.</returns>
136+
public IRepository<TEntity, TKey> Create<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
137+
{
138+
return CreateAsync<TEntity, TKey>(options);
139+
}
140+
141+
#endregion
142+
143+
#region Implementation of IRepositoryFactoryAsync
144+
145+
/// <summary>
146+
/// Creates a new asynchronous repository for the specified entity type.
147+
/// </summary>
148+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
149+
/// <returns>The new asynchronous repository.</returns>
150+
public IRepositoryAsync<TEntity> CreateAsync<TEntity>() where TEntity : class
151+
{
152+
if (_options == null)
153+
throw new InvalidOperationException("No options have been provided.");
154+
155+
return CreateAsync<TEntity>(_options);
156+
}
157+
158+
/// <summary>
159+
/// Creates a new asynchronous repository for the specified entity and primary key type.
160+
/// </summary>
161+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
162+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
163+
/// <returns>The new asynchronous repository.</returns>
164+
public IRepositoryAsync<TEntity, TKey> CreateAsync<TEntity, TKey>() where TEntity : class
165+
{
166+
if (_options == null)
167+
throw new InvalidOperationException("No options have been provided.");
168+
169+
return CreateAsync<TEntity, TKey>(_options);
170+
}
171+
172+
/// <summary>
173+
/// Creates a new asynchronous repository for the specified entity type.
174+
/// </summary>
175+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
176+
/// <param name="options">The options.</param>
177+
/// <returns>The new asynchronous repository.</returns>
178+
public IRepositoryAsync<TEntity> CreateAsync<TEntity>(Dictionary<string, object> options) where TEntity : class
130179
{
131180
GetOptions(options, out string providerName, out string connectionString, out IEnumerable<IRepositoryInterceptor> interceptors);
132181

@@ -136,13 +185,13 @@ public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options)
136185
}
137186

138187
/// <summary>
139-
/// Creates a new repository for the specified entity and primary key type.
188+
/// Creates a new asynchronous repository for the specified entity and primary key type.
140189
/// </summary>
141190
/// <typeparam name="TEntity">The type of the entity.</typeparam>
142191
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
143192
/// <param name="options">The options.</param>
144-
/// <returns>The new repository.</returns>
145-
public IRepository<TEntity, TKey> Create<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
193+
/// <returns>The new asynchronous repository.</returns>
194+
public IRepositoryAsync<TEntity, TKey> CreateAsync<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
146195
{
147196
GetOptions(options, out string providerName, out string connectionString, out IEnumerable<IRepositoryInterceptor> interceptors);
148197

src/DotNetToolkit.Repository.Csv/CsvRepositoryFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DotNetToolkit.Repository.Csv
22
{
3+
using Factories;
34
using Interceptors;
45
using System;
56
using System.Collections.Generic;

src/DotNetToolkit.Repository.EntityFramework/EfRepositoryFactory.cs

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
namespace DotNetToolkit.Repository.EntityFramework
22
{
3+
using Factories;
34
using Interceptors;
45
using System;
56
using System.Collections.Generic;
67
using System.Data.Entity;
78
using System.Data.Entity.Infrastructure;
89

910
/// <summary>
10-
/// An implementation of <see cref="IRepositoryFactory" />.
11+
/// An implementation of <see cref="IRepositoryFactoryAsync" />.
1112
/// </summary>
12-
public class EfRepositoryFactory : IRepositoryFactory
13+
public class EfRepositoryFactory : IRepositoryFactoryAsync
1314
{
1415
#region Fields
1516

@@ -123,10 +124,7 @@ private static void GetOptions(Dictionary<string, object> options, out DbContext
123124
/// <returns>The new repository.</returns>
124125
public IRepository<TEntity> Create<TEntity>() where TEntity : class
125126
{
126-
if (_options == null)
127-
throw new InvalidOperationException("No options have been provided.");
128-
129-
return Create<TEntity>(_options);
127+
return CreateAsync<TEntity>();
130128
}
131129

132130
/// <summary>
@@ -137,10 +135,7 @@ public IRepository<TEntity> Create<TEntity>() where TEntity : class
137135
/// <returns>The new repository.</returns>
138136
public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
139137
{
140-
if (_options == null)
141-
throw new InvalidOperationException("No options have been provided.");
142-
143-
return Create<TEntity, TKey>(_options);
138+
return CreateAsync<TEntity, TKey>();
144139
}
145140

146141
/// <summary>
@@ -151,9 +146,7 @@ public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
151146
/// <returns>The new repository.</returns>
152147
public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options) where TEntity : class
153148
{
154-
GetOptions(options, out DbContext context, out IEnumerable<IRepositoryInterceptor> interceptors);
155-
156-
return new EfRepository<TEntity>(context, interceptors);
149+
return CreateAsync<TEntity>(options);
157150
}
158151

159152
/// <summary>
@@ -164,6 +157,62 @@ public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options)
164157
/// <param name="options">The options.</param>
165158
/// <returns>The new repository.</returns>
166159
public IRepository<TEntity, TKey> Create<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
160+
{
161+
return CreateAsync<TEntity, TKey>(options);
162+
}
163+
164+
#endregion
165+
166+
#region Implementation of IRepositoryFactoryAsync
167+
168+
/// <summary>
169+
/// Creates a new asynchronous repository for the specified entity type.
170+
/// </summary>
171+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
172+
/// <returns>The new asynchronous repository.</returns>
173+
public IRepositoryAsync<TEntity> CreateAsync<TEntity>() where TEntity : class
174+
{
175+
if (_options == null)
176+
throw new InvalidOperationException("No options have been provided.");
177+
178+
return CreateAsync<TEntity>(_options);
179+
}
180+
181+
/// <summary>
182+
/// Creates a new asynchronous repository for the specified entity and primary key type.
183+
/// </summary>
184+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
185+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
186+
/// <returns>The new asynchronous repository.</returns>
187+
public IRepositoryAsync<TEntity, TKey> CreateAsync<TEntity, TKey>() where TEntity : class
188+
{
189+
if (_options == null)
190+
throw new InvalidOperationException("No options have been provided.");
191+
192+
return CreateAsync<TEntity, TKey>(_options);
193+
}
194+
195+
/// <summary>
196+
/// Creates a new asynchronous repository for the specified entity type.
197+
/// </summary>
198+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
199+
/// <param name="options">The options.</param>
200+
/// <returns>The new asynchronous repository.</returns>
201+
public IRepositoryAsync<TEntity> CreateAsync<TEntity>(Dictionary<string, object> options) where TEntity : class
202+
{
203+
GetOptions(options, out DbContext context, out IEnumerable<IRepositoryInterceptor> interceptors);
204+
205+
return new EfRepository<TEntity>(context, interceptors);
206+
}
207+
208+
/// <summary>
209+
/// Creates a new asynchronous repository for the specified entity and primary key type.
210+
/// </summary>
211+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
212+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
213+
/// <param name="options">The options.</param>
214+
/// <returns>The new asynchronous repository.</returns>
215+
public IRepositoryAsync<TEntity, TKey> CreateAsync<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
167216
{
168217
GetOptions(options, out DbContext context, out IEnumerable<IRepositoryInterceptor> interceptors);
169218

src/DotNetToolkit.Repository.EntityFrameworkCore/EfCoreRepositoryFactory.cs

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
namespace DotNetToolkit.Repository.EntityFrameworkCore
22
{
3+
using Factories;
34
using Interceptors;
45
using Microsoft.EntityFrameworkCore;
56
using System;
67
using System.Collections.Generic;
78

89
/// <summary>
9-
/// An implementation of <see cref="IRepositoryFactory" />.
10+
/// An implementation of <see cref="IRepositoryFactoryAsync" />.
1011
/// </summary>
11-
public class EfCoreRepositoryFactory : IRepositoryFactory
12+
public class EfCoreRepositoryFactory : IRepositoryFactoryAsync
1213
{
1314
#region Fields
1415

@@ -107,10 +108,7 @@ private static void GetOptions(Dictionary<string, object> options, out DbContext
107108
/// <returns>The new repository.</returns>
108109
public IRepository<TEntity> Create<TEntity>() where TEntity : class
109110
{
110-
if (_options == null)
111-
throw new InvalidOperationException("No options have been provided.");
112-
113-
return Create<TEntity>(_options);
111+
return CreateAsync<TEntity>();
114112
}
115113

116114
/// <summary>
@@ -121,10 +119,7 @@ public IRepository<TEntity> Create<TEntity>() where TEntity : class
121119
/// <returns>The new repository.</returns>
122120
public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
123121
{
124-
if (_options == null)
125-
throw new InvalidOperationException("No options have been provided.");
126-
127-
return Create<TEntity, TKey>(_options);
122+
return CreateAsync<TEntity, TKey>();
128123
}
129124

130125
/// <summary>
@@ -135,9 +130,7 @@ public IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class
135130
/// <returns>The new repository.</returns>
136131
public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options) where TEntity : class
137132
{
138-
GetOptions(options, out DbContext context, out IEnumerable<IRepositoryInterceptor> interceptors);
139-
140-
return new EfCoreRepository<TEntity>(context, interceptors);
133+
return CreateAsync<TEntity>(options);
141134
}
142135

143136
/// <summary>
@@ -148,6 +141,62 @@ public IRepository<TEntity> Create<TEntity>(Dictionary<string, object> options)
148141
/// <param name="options">The options.</param>
149142
/// <returns>The new repository.</returns>
150143
public IRepository<TEntity, TKey> Create<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
144+
{
145+
return CreateAsync<TEntity, TKey>(options);
146+
}
147+
148+
#endregion
149+
150+
#region Implementation of IRepositoryFactoryAsync
151+
152+
/// <summary>
153+
/// Creates a new asynchronous repository for the specified entity type.
154+
/// </summary>
155+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
156+
/// <returns>The new asynchronous repository.</returns>
157+
public IRepositoryAsync<TEntity> CreateAsync<TEntity>() where TEntity : class
158+
{
159+
if (_options == null)
160+
throw new InvalidOperationException("No options have been provided.");
161+
162+
return CreateAsync<TEntity>(_options);
163+
}
164+
165+
/// <summary>
166+
/// Creates a new asynchronous repository for the specified entity and primary key type.
167+
/// </summary>
168+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
169+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
170+
/// <returns>The new asynchronous repository.</returns>
171+
public IRepositoryAsync<TEntity, TKey> CreateAsync<TEntity, TKey>() where TEntity : class
172+
{
173+
if (_options == null)
174+
throw new InvalidOperationException("No options have been provided.");
175+
176+
return CreateAsync<TEntity, TKey>(_options);
177+
}
178+
179+
/// <summary>
180+
/// Creates a new asynchronous repository for the specified entity type.
181+
/// </summary>
182+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
183+
/// <param name="options">The options.</param>
184+
/// <returns>The new asynchronous repository.</returns>
185+
public IRepositoryAsync<TEntity> CreateAsync<TEntity>(Dictionary<string, object> options) where TEntity : class
186+
{
187+
GetOptions(options, out DbContext context, out IEnumerable<IRepositoryInterceptor> interceptors);
188+
189+
return new EfCoreRepository<TEntity>(context, interceptors);
190+
}
191+
192+
/// <summary>
193+
/// Creates a new asynchronous repository for the specified entity and primary key type.
194+
/// </summary>
195+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
196+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
197+
/// <param name="options">The options.</param>
198+
/// <returns>The new asynchronous repository.</returns>
199+
public IRepositoryAsync<TEntity, TKey> CreateAsync<TEntity, TKey>(Dictionary<string, object> options) where TEntity : class
151200
{
152201
GetOptions(options, out DbContext context, out IEnumerable<IRepositoryInterceptor> interceptors);
153202

src/DotNetToolkit.Repository.InMemory/InMemoryRepositoryFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DotNetToolkit.Repository.InMemory
22
{
3+
using Factories;
34
using Interceptors;
45
using System;
56
using System.Collections.Generic;

src/DotNetToolkit.Repository.Json/JsonRepositoryFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DotNetToolkit.Repository.Json
22
{
3+
using Factories;
34
using Interceptors;
45
using System;
56
using System.Collections.Generic;

src/DotNetToolkit.Repository.Xml/XmlRepositoryFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace DotNetToolkit.Repository.Xml
22
{
3+
using Factories;
34
using Interceptors;
45
using System;
56
using System.Collections.Generic;

src/DotNetToolkit.Repository/IRepositoryFactory.cs renamed to src/DotNetToolkit.Repository/Factories/IRepositoryFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace DotNetToolkit.Repository
1+
namespace DotNetToolkit.Repository.Factories
22
{
33
using System.Collections.Generic;
44

0 commit comments

Comments
 (0)