Skip to content

Commit 4e6cfbe

Browse files
(GH-601) Prevented unit of work from being a type of repository factory
1 parent 4c50c82 commit 4e6cfbe

File tree

2 files changed

+68
-33
lines changed

2 files changed

+68
-33
lines changed

src/DotNetToolkit.Repository/Transactions/IUnitOfWork.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,49 @@
66
/// Maintains business objects in-memory which have been changed (inserted, updated, or deleted) in a single transaction.
77
/// Once the transaction is completed, the changes will be sent to the database in one single unit of work.
88
/// </summary>
9-
/// <seealso cref="IRepositoryFactory" />
109
/// <seealso cref="System.IDisposable" />
11-
public interface IUnitOfWork : IRepositoryFactory, IDisposable
10+
public interface IUnitOfWork : IDisposable
1211
{
12+
/// <summary>
13+
/// Creates a new repository for the specified entity type.
14+
/// </summary>
15+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
16+
/// <returns>The new repository.</returns>
17+
IRepository<TEntity> Create<TEntity>() where TEntity : class;
18+
19+
/// <summary>
20+
/// Creates a new repository for the specified entity and primary key type.
21+
/// </summary>
22+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
23+
/// <typeparam name="TKey">The type of the key primary key value.</typeparam>
24+
/// <returns>The new repository.</returns>
25+
IRepository<TEntity, TKey> Create<TEntity, TKey>() where TEntity : class;
26+
27+
/// <summary>
28+
/// Creates a new repository for the specified entity and a composite primary key type.
29+
/// </summary>
30+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
31+
/// <typeparam name="TKey1">The type of the first part of the composite primary key.</typeparam>
32+
/// <typeparam name="TKey2">The type of the second part of the composite primary key.</typeparam>
33+
/// <returns>The new repository.</returns>
34+
IRepository<TEntity, TKey1, TKey2> Create<TEntity, TKey1, TKey2>() where TEntity : class;
35+
36+
/// <summary>
37+
/// Creates a new repository for the specified entity and a composite primary key type.
38+
/// </summary>
39+
/// <typeparam name="TEntity">The type of the entity.</typeparam>
40+
/// <typeparam name="TKey1">The type of the first part of the composite primary key.</typeparam>
41+
/// <typeparam name="TKey2">The type of the second part of the composite primary key.</typeparam>
42+
/// <typeparam name="TKey3">The type of the third part of the composite primary key.</typeparam>
43+
/// <returns>The new repository.</returns>
44+
IRepository<TEntity, TKey1, TKey2, TKey3> Create<TEntity, TKey1, TKey2, TKey3>() where TEntity : class;
45+
46+
/// <summary>
47+
/// Creates a new repository for the specified type.
48+
/// </summary>
49+
/// <returns>The new repository.</returns>
50+
T CreateInstance<T>() where T : class;
51+
1352
/// <summary>
1453
/// Commits all changes made in this unit of work.
1554
/// </summary>

src/DotNetToolkit.Repository/Transactions/UnitOfWork.cs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -94,37 +94,6 @@ private void Initialize([NotNull] IRepositoryOptions options)
9494

9595
#region Implementation of IUnitOfWork
9696

97-
/// <summary>
98-
/// Commits all changes made in this unit of work.
99-
/// </summary>
100-
public virtual void Commit()
101-
{
102-
ThrowIfDisposed();
103-
104-
if (_transactionManager == null)
105-
throw new InvalidOperationException("The transaction has already been committed.");
106-
107-
_transactionManager.Commit();
108-
_transactionManager = null;
109-
}
110-
111-
#endregion
112-
113-
#region Implementation of IDisposable
114-
115-
/// <summary>
116-
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
117-
/// </summary>
118-
public void Dispose()
119-
{
120-
Dispose(true);
121-
GC.SuppressFinalize(this);
122-
}
123-
124-
#endregion
125-
126-
#region Implementation of IRepositoryFactory
127-
12897
/// <summary>
12998
/// Creates a new repository for the specified entity type.
13099
/// </summary>
@@ -191,6 +160,33 @@ public T CreateInstance<T>() where T : class
191160
return (T)Activator.CreateInstance(typeof(T), new object[] { _options });
192161
}
193162

163+
/// <summary>
164+
/// Commits all changes made in this unit of work.
165+
/// </summary>
166+
public virtual void Commit()
167+
{
168+
ThrowIfDisposed();
169+
170+
if (_transactionManager == null)
171+
throw new InvalidOperationException("The transaction has already been committed.");
172+
173+
_transactionManager.Commit();
174+
_transactionManager = null;
175+
}
176+
177+
#endregion
178+
179+
#region Implementation of IDisposable
180+
181+
/// <summary>
182+
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
183+
/// </summary>
184+
public void Dispose()
185+
{
186+
Dispose(true);
187+
GC.SuppressFinalize(this);
188+
}
189+
194190
#endregion
195191

196192
#region Nested Type: RepositoryContextFactory

0 commit comments

Comments
 (0)