U4-6147 - cleanup units of work
This commit is contained in:
@@ -8,17 +8,14 @@
|
||||
/// mechanism.</remarks>
|
||||
internal class FileUnitOfWork : UnitOfWorkBase
|
||||
{
|
||||
private readonly RepositoryFactory _factory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NPocoUnitOfWork"/> class with a a repository factory.
|
||||
/// </summary>
|
||||
/// <param name="factory">A repository factory.</param>
|
||||
/// <remarks>This should be used by the FileUnitOfWorkProvider exclusively.</remarks>
|
||||
public FileUnitOfWork(RepositoryFactory factory)
|
||||
{
|
||||
_factory = factory;
|
||||
}
|
||||
: base(factory)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a repository.
|
||||
@@ -28,7 +25,7 @@
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
public override TRepository CreateRepository<TRepository>(string name = null)
|
||||
{
|
||||
return _factory.CreateRepository<TRepository>(this, name);
|
||||
return Factory.CreateRepository<TRepository>(this, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// <summary>
|
||||
/// Begins the unit of work.
|
||||
/// </summary>
|
||||
/// <remarks>When a unit of work begins, a local transaction scope is created at database level.
|
||||
/// <remarks>When a unit of work begins, a local transaction scope is created at database level.
|
||||
/// This is useful eg when reading entities before creating, updating or deleting, and the read
|
||||
/// needs to be part of the transaction. Flushing or completing the unit of work automatically
|
||||
/// begins the transaction (so no need to call Begin if not necessary).</remarks>
|
||||
@@ -58,8 +58,11 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// before it is disposed, all queued operations are cleared and the scope is rolled back (and also
|
||||
/// higher level transactions if any).
|
||||
/// Whether this actually commits or rolls back the transaction depends on whether the transaction scope
|
||||
/// is part of a higher level transactions. The database transaction is committed or rolled back only
|
||||
/// is part of a higher level transactions. The database transaction is committed or rolled back only
|
||||
/// when the upper level scope is disposed.
|
||||
/// If any operation is added to the unit of work after it has been completed, then its completion
|
||||
/// status is resetted. So in a way it could be possible to always complete and never flush, but flush
|
||||
/// is preferred when appropriate to indicate that you understand what you are doing.
|
||||
/// </remarks>
|
||||
void Complete();
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// </summary>
|
||||
internal class NPocoUnitOfWork : UnitOfWorkBase, IDatabaseUnitOfWork
|
||||
{
|
||||
private readonly RepositoryFactory _factory;
|
||||
private ITransaction _transaction;
|
||||
|
||||
/// <summary>
|
||||
@@ -19,9 +18,9 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// <param name="factory">A repository factory.</param>
|
||||
/// <remarks>This should be used by the NPocoUnitOfWorkProvider exclusively.</remarks>
|
||||
internal NPocoUnitOfWork(UmbracoDatabase database, RepositoryFactory factory)
|
||||
: base(factory)
|
||||
{
|
||||
Database = database;
|
||||
_factory = factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,7 +36,7 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
/// <returns>The created repository for the unit of work.</returns>
|
||||
public override TRepository CreateRepository<TRepository>(string name = null)
|
||||
{
|
||||
return _factory.CreateRepository<TRepository>(this, name);
|
||||
return Factory.CreateRepository<TRepository>(this, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,8 +9,15 @@ namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
private readonly Queue<Operation> _operations = new Queue<Operation>();
|
||||
|
||||
// fixme eventually kill this
|
||||
public virtual T CreateRepository<T>(string name = null) where T:IRepository { throw new NotImplementedException(); }
|
||||
protected UnitOfWorkBase(RepositoryFactory factory)
|
||||
{
|
||||
Factory = factory;
|
||||
}
|
||||
|
||||
protected RepositoryFactory Factory { get; }
|
||||
|
||||
public abstract TRepository CreateRepository<TRepository>(string name = null)
|
||||
where TRepository : IRepository;
|
||||
|
||||
/// <summary>
|
||||
/// Registers an entity to be added as part of this unit of work.
|
||||
|
||||
Reference in New Issue
Block a user