Refactoring Unit of Work and its dependency on the datastore.
Removing legacy test project from solution.
This commit is contained in:
@@ -18,13 +18,13 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
private const string NodeObjectType = "C66BA18E-EAF3-4CFF-8A22-41B16D66A972";
|
||||
private readonly IContentTypeRepository _contentTypeRepository;
|
||||
|
||||
public ContentRepository(IUnitOfWork work, IContentTypeRepository contentTypeRepository)
|
||||
public ContentRepository(IUnitOfWork<Database> work, IContentTypeRepository contentTypeRepository)
|
||||
: base(work)
|
||||
{
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
}
|
||||
|
||||
internal ContentRepository(IUnitOfWork work, IContentTypeRepository contentTypeRepository, IRepositoryCacheProvider registry)
|
||||
internal ContentRepository(IUnitOfWork<Database> work, IContentTypeRepository contentTypeRepository, IRepositoryCacheProvider registry)
|
||||
: base(work, registry)
|
||||
{
|
||||
_contentTypeRepository = contentTypeRepository;
|
||||
|
||||
@@ -62,6 +62,6 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// Sets the Unit Of Work for the Repository
|
||||
/// </summary>
|
||||
/// <param name="work"></param>
|
||||
void SetUnitOfWork(IUnitOfWork work);
|
||||
void SetUnitOfWork<T>(IUnitOfWork<T> work);
|
||||
}
|
||||
}
|
||||
@@ -12,23 +12,24 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// Represent an abstract Repository, which is the base of the Repository implementations
|
||||
/// </summary>
|
||||
/// <typeparam name="TEntity"></typeparam>
|
||||
internal abstract class Repository<TEntity> : IDisposable, IRepository<TEntity> where TEntity : class, IAggregateRoot
|
||||
internal abstract class Repository<TEntity> : IDisposable,
|
||||
IRepository<TEntity> where TEntity : class, IAggregateRoot
|
||||
{
|
||||
private IUnitOfWork _work;
|
||||
private IUnitOfWork<Database> _work;
|
||||
private readonly IRepositoryCacheProvider _cache;
|
||||
|
||||
protected Repository(IUnitOfWork work)
|
||||
protected Repository(IUnitOfWork<Database> work)
|
||||
: this(work, RuntimeCacheProvider.Current)
|
||||
{
|
||||
}
|
||||
|
||||
internal Repository(IUnitOfWork work, IRepositoryCacheProvider cache)
|
||||
internal Repository(IUnitOfWork<Database> work, IRepositoryCacheProvider cache)
|
||||
{
|
||||
_work = work;
|
||||
_cache = cache;
|
||||
}
|
||||
|
||||
internal IUnitOfWork UnitOfWork
|
||||
internal IUnitOfWork<Database> UnitOfWork
|
||||
{
|
||||
get { return _work; }
|
||||
}
|
||||
@@ -127,9 +128,9 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return PerformCount(query);
|
||||
}
|
||||
|
||||
public void SetUnitOfWork(IUnitOfWork work)
|
||||
public void SetUnitOfWork<T>(IUnitOfWork<T> work)
|
||||
{
|
||||
_work = work;
|
||||
_work = work as IUnitOfWork<Database>;
|
||||
}
|
||||
|
||||
public virtual void Dispose()
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
public interface IUnitOfWork : IDisposable
|
||||
public interface IUnitOfWork<T> : IDisposable
|
||||
{
|
||||
void Commit();
|
||||
Database Storage { get; } //TODO consider replacing 'Database' with a datastorage adapter, so there is no direct dependency on PetaPoco
|
||||
T Storage { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
public interface IUnitOfWorkProvider
|
||||
public interface IUnitOfWorkProvider<T>
|
||||
{
|
||||
IUnitOfWork GetUnitOfWork();
|
||||
IUnitOfWork<T> GetUnitOfWork();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
internal class PetaPocoUnitOfWork : IUnitOfWork<Database>
|
||||
{
|
||||
private readonly Transaction _petaTransaction;
|
||||
private readonly Database _storage;
|
||||
|
||||
public PetaPocoUnitOfWork()
|
||||
{
|
||||
_storage = new Database(@"server=.\SQLEXPRESS;database=UmbracoPOC-Site;user id=umbraco;password=umbraco", "System.Data.SqlClient");
|
||||
_petaTransaction = new Transaction(_storage);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_petaTransaction.Dispose();
|
||||
}
|
||||
|
||||
public void Commit()
|
||||
{
|
||||
_petaTransaction.Complete();
|
||||
}
|
||||
|
||||
public Database Storage
|
||||
{
|
||||
get { return _storage; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Umbraco.Core.Persistence.UnitOfWork
|
||||
{
|
||||
internal class PetaPocoUnitOfWorkProvider : IUnitOfWorkProvider<Database>
|
||||
{
|
||||
public IUnitOfWork<Database> GetUnitOfWork()
|
||||
{
|
||||
return new PetaPocoUnitOfWork();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,6 +99,8 @@
|
||||
<Compile Include="Persistence\Repositories\Repository.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\IUnitOfWork.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\IUnitOfWorkProvider.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\PetaPocoUnitOfWork.cs" />
|
||||
<Compile Include="Persistence\UnitOfWork\PetaPocoUnitOfWorkProvider.cs" />
|
||||
<Compile Include="PublishedContentExtensions.cs" />
|
||||
<Compile Include="Dictionary\ICultureDictionary.cs" />
|
||||
<Compile Include="Dynamics\ClassFactory.cs" />
|
||||
|
||||
@@ -52,8 +52,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.MacroEngines", "umb
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "umbraco.MacroEngines.Iron", "umbraco.MacroEngines.Iron\umbraco.MacroEngines.Iron.csproj", "{98CBA7E2-1B62-497C-8AA3-B868704068D7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.LegacyTests", "..\test\umbraco.Test\Umbraco.LegacyTests.csproj", "{6277C9FB-3A9A-4537-AA86-82DA9B2527FD}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{B5BD12C1-A454-435E-8A46-FF4A364C0382}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Umbraco.Core", "Umbraco.Core\Umbraco.Core.csproj", "{31785BC3-256C-4613-B2F5-A1B0BDDED8C1}"
|
||||
@@ -123,10 +121,6 @@ Global
|
||||
{98CBA7E2-1B62-497C-8AA3-B868704068D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98CBA7E2-1B62-497C-8AA3-B868704068D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98CBA7E2-1B62-497C-8AA3-B868704068D7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{6277C9FB-3A9A-4537-AA86-82DA9B2527FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6277C9FB-3A9A-4537-AA86-82DA9B2527FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6277C9FB-3A9A-4537-AA86-82DA9B2527FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6277C9FB-3A9A-4537-AA86-82DA9B2527FD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{31785BC3-256C-4613-B2F5-A1B0BDDED8C1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -144,7 +138,6 @@ Global
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{6277C9FB-3A9A-4537-AA86-82DA9B2527FD} = {B5BD12C1-A454-435E-8A46-FF4A364C0382}
|
||||
{5D3B8245-ADA6-453F-A008-50ED04BFE770} = {B5BD12C1-A454-435E-8A46-FF4A364C0382}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
Reference in New Issue
Block a user