Refactoring repository inheritance

This commit is contained in:
Morten@Thinkpad-X220
2012-10-09 06:59:18 -02:00
parent a459cb95c4
commit 4abc8075ab
14 changed files with 53 additions and 35 deletions

View File

@@ -4,7 +4,7 @@ using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IContentRepository : IRepository<int, IContent>
public interface IContentRepository : IRepositoryQueryable<int, IContent>
{
IEnumerable<IContent> GetAllVersions(int id);
IContent GetByVersion(int id, Guid versionId);

View File

@@ -2,7 +2,7 @@
namespace Umbraco.Core.Persistence.Repositories
{
public interface IContentTypeRepository : IRepository<int, IContentType>
public interface IContentTypeRepository : IRepositoryQueryable<int, IContentType>
{
}

View File

@@ -2,7 +2,7 @@
namespace Umbraco.Core.Persistence.Repositories
{
public interface IDataTypeDefinitionRepository : IRepository<int, DataTypeDefinition>
public interface IDataTypeDefinitionRepository : IRepositoryQueryable<int, DataTypeDefinition>
{
}

View File

@@ -2,7 +2,7 @@
namespace Umbraco.Core.Persistence.Repositories
{
internal interface IDictionaryRepository : IRepository<int, DictionaryItem>
internal interface IDictionaryRepository : IRepositoryQueryable<int, DictionaryItem>
{
}

View File

@@ -2,7 +2,7 @@
namespace Umbraco.Core.Persistence.Repositories
{
public interface ILanguageRepository : IRepository<int, Language>
public interface ILanguageRepository : IRepositoryQueryable<int, Language>
{
}

View File

@@ -6,7 +6,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// Defines the Macro Repository, which exposes CRUD operations for <see cref="IMacro"/>
/// </summary>
/// <remarks>Uses string Alias as the Id type</remarks>
public interface IMacroRepository : IRepository<string, IMacro>
public interface IMacroRepository : IRepositoryQueryable<string, IMacro>
{
}

View File

@@ -2,7 +2,7 @@
namespace Umbraco.Core.Persistence.Repositories
{
public interface IRelationRepository : IRepository<int, Relation>
public interface IRelationRepository : IRepositoryQueryable<int, Relation>
{
}

View File

@@ -2,7 +2,7 @@
namespace Umbraco.Core.Persistence.Repositories
{
public interface IRelationTypeRepository : IRepository<int, RelationType>
public interface IRelationTypeRepository : IRepositoryQueryable<int, RelationType>
{
}

View File

@@ -0,0 +1,29 @@
using System.Collections.Generic;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Querying;
namespace Umbraco.Core.Persistence.Repositories
{
/// <summary>
/// Defines the implementation of a Repository
/// </summary>
/// <typeparam name="TEntity">Type of <see cref="IAggregateRoot"/> entity for which the repository is used</typeparam>
/// <typeparam name="TId">Type of the Id used for this entity</typeparam>
public interface IRepositoryQueryable<TId, TEntity> : ISimpleRepository<TId, TEntity>
where TEntity : IAggregateRoot
{
/// <summary>
/// Gets all entities of the spefified type and query
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
IEnumerable<TEntity> GetByQuery(IQuery<TEntity> query);
/// <summary>
/// Returns the count for the specified query
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
int Count(IQuery<TEntity> query);
}
}

View File

@@ -0,0 +1,9 @@
using Umbraco.Core.Models;
namespace Umbraco.Core.Persistence.Repositories
{
public interface IScriptRepository : ISimpleRepository<string, Script>
{
}
}

View File

@@ -1,17 +1,9 @@
using System.Collections.Generic;
using Umbraco.Core.Models.EntityBase;
using Umbraco.Core.Persistence.Querying;
using Umbraco.Core.Persistence.UnitOfWork;
namespace Umbraco.Core.Persistence.Repositories
{
/// <summary>
/// Defines the implementation of a Repository
/// </summary>
/// <typeparam name="TEntity">Type of <see cref="IAggregateRoot"/> entity for which the repository is used</typeparam>
/// <typeparam name="TId">Type of the Id used for this entity</typeparam>
public interface IRepository<TId, TEntity>
where TEntity : IAggregateRoot
public interface ISimpleRepository<TId, TEntity>
{
/// <summary>
/// Adds or Updates an Entity
@@ -39,13 +31,6 @@ namespace Umbraco.Core.Persistence.Repositories
/// <returns></returns>
IEnumerable<TEntity> GetAll(params TId[] ids);
/// <summary>
/// Gets all entities of the spefified type and query
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
IEnumerable<TEntity> GetByQuery(IQuery<TEntity> query);
/// <summary>
/// Boolean indicating whether an Entity with the specified Id exists
/// </summary>
@@ -53,13 +38,6 @@ namespace Umbraco.Core.Persistence.Repositories
/// <returns></returns>
bool Exists(TId id);
/// <summary>
/// Returns the count for the specified query
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
int Count(IQuery<TEntity> query);
/// <summary>
/// Sets the Unit Of Work for the Repository
/// </summary>

View File

@@ -13,7 +13,7 @@ namespace Umbraco.Core.Persistence.Repositories
/// </summary>
/// <typeparam name="TEntity">Type of <see cref="IAggregateRoot"/> entity for which the repository is used</typeparam>
/// <typeparam name="TId">Type of the Id used for this entity</typeparam>
internal abstract class RepositoryBase<TId, TEntity> : IRepository<TId, TEntity>,
internal abstract class RepositoryBase<TId, TEntity> : IRepositoryQueryable<TId, TEntity>,
IUnitOfWorkRepository where TEntity : IAggregateRoot
{
private IUnitOfWork _work;

View File

@@ -23,7 +23,7 @@ namespace Umbraco.Core.Persistence
//- If type exists check dependencies, create new object, add it to dictionary and return it
//If we have come this far the correct types wasn't found and we throw an exception
internal static TRepository ResolveByType<TRepository, TEntity, TId>(IUnitOfWork unitOfWork)
where TRepository : class, IRepository<TId, TEntity>
where TRepository : class, IRepositoryQueryable<TId, TEntity>
where TEntity : class, IAggregateRoot
{
//Initialize the provider's default value
@@ -36,7 +36,7 @@ namespace Umbraco.Core.Persistence
if (Repositories.ContainsKey(interfaceShortName))
{
repository = (TRepository)Repositories[interfaceShortName];
if (unitOfWork != null && repository.GetType().IsSubclassOf(typeof(IRepository<TId, TEntity>)))
if (unitOfWork != null && repository.GetType().IsSubclassOf(typeof(IRepositoryQueryable<TId, TEntity>)))
{
repository.SetUnitOfWork(unitOfWork);
}

View File

@@ -129,8 +129,10 @@
<Compile Include="Persistence\Repositories\IMacroRepository.cs" />
<Compile Include="Persistence\Repositories\IRelationRepository.cs" />
<Compile Include="Persistence\Repositories\IRelationTypeRepository.cs" />
<Compile Include="Persistence\Repositories\IRepository.cs" />
<Compile Include="Persistence\Repositories\IRepositoryQueryable.cs" />
<Compile Include="Persistence\Relators\TabPropertyTypeRelator.cs" />
<Compile Include="Persistence\Repositories\IScriptRepository.cs" />
<Compile Include="Persistence\Repositories\ISimpleRepository.cs" />
<Compile Include="Persistence\Repositories\LanguageRepository.cs" />
<Compile Include="Persistence\Repositories\MacroRepository.cs" />
<Compile Include="Persistence\Repositories\PetaPocoRepositoryBase.cs" />