From 4abc8075ab40bc752e2f6968887a71f28111310f Mon Sep 17 00:00:00 2001 From: "Morten@Thinkpad-X220" Date: Tue, 9 Oct 2012 06:59:18 -0200 Subject: [PATCH] Refactoring repository inheritance --- .../Repositories/IContentRepository.cs | 2 +- .../Repositories/IContentTypeRepository.cs | 2 +- .../IDataTypeDefinitionRepository.cs | 2 +- .../Repositories/IDictionaryRepository.cs | 2 +- .../Repositories/ILanguageRepository.cs | 2 +- .../Repositories/IMacroRepository.cs | 2 +- .../Repositories/IRelationRepository.cs | 2 +- .../Repositories/IRelationTypeRepository.cs | 2 +- .../Repositories/IRepositoryQueryable.cs | 29 +++++++++++++++++++ .../Repositories/IScriptRepository.cs | 9 ++++++ .../{IRepository.cs => ISimpleRepository.cs} | 24 +-------------- .../Repositories/RepositoryBase.cs | 2 +- .../Persistence/RepositoryResolver.cs | 4 +-- src/Umbraco.Core/Umbraco.Core.csproj | 4 ++- 14 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 src/Umbraco.Core/Persistence/Repositories/IRepositoryQueryable.cs create mode 100644 src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs rename src/Umbraco.Core/Persistence/Repositories/{IRepository.cs => ISimpleRepository.cs} (56%) diff --git a/src/Umbraco.Core/Persistence/Repositories/IContentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IContentRepository.cs index 76c992cb65..31cec0322e 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IContentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IContentRepository.cs @@ -4,7 +4,7 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Persistence.Repositories { - public interface IContentRepository : IRepository + public interface IContentRepository : IRepositoryQueryable { IEnumerable GetAllVersions(int id); IContent GetByVersion(int id, Guid versionId); diff --git a/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs index dcdabeb0e1..abbf8c95a0 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IContentTypeRepository.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Persistence.Repositories { - public interface IContentTypeRepository : IRepository + public interface IContentTypeRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs index 2bd50d26c3..01e3faaa9a 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IDataTypeDefinitionRepository.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Persistence.Repositories { - public interface IDataTypeDefinitionRepository : IRepository + public interface IDataTypeDefinitionRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/IDictionaryRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IDictionaryRepository.cs index 2db4046efc..5d762eec00 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IDictionaryRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IDictionaryRepository.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Persistence.Repositories { - internal interface IDictionaryRepository : IRepository + internal interface IDictionaryRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/ILanguageRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ILanguageRepository.cs index 3273df2d7a..303e573d54 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ILanguageRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ILanguageRepository.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Persistence.Repositories { - public interface ILanguageRepository : IRepository + public interface ILanguageRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/IMacroRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IMacroRepository.cs index 1ac62e4a8d..4f028a78a2 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IMacroRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IMacroRepository.cs @@ -6,7 +6,7 @@ namespace Umbraco.Core.Persistence.Repositories /// Defines the Macro Repository, which exposes CRUD operations for /// /// Uses string Alias as the Id type - public interface IMacroRepository : IRepository + public interface IMacroRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs index 4a359c0322..80162e15b8 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IRelationRepository.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Persistence.Repositories { - public interface IRelationRepository : IRepository + public interface IRelationRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/IRelationTypeRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IRelationTypeRepository.cs index d1c23e0122..e4ca156a94 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IRelationTypeRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/IRelationTypeRepository.cs @@ -2,7 +2,7 @@ namespace Umbraco.Core.Persistence.Repositories { - public interface IRelationTypeRepository : IRepository + public interface IRelationTypeRepository : IRepositoryQueryable { } diff --git a/src/Umbraco.Core/Persistence/Repositories/IRepositoryQueryable.cs b/src/Umbraco.Core/Persistence/Repositories/IRepositoryQueryable.cs new file mode 100644 index 0000000000..1d5131cc08 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Repositories/IRepositoryQueryable.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using Umbraco.Core.Models.EntityBase; +using Umbraco.Core.Persistence.Querying; + +namespace Umbraco.Core.Persistence.Repositories +{ + /// + /// Defines the implementation of a Repository + /// + /// Type of entity for which the repository is used + /// Type of the Id used for this entity + public interface IRepositoryQueryable : ISimpleRepository + where TEntity : IAggregateRoot + { + /// + /// Gets all entities of the spefified type and query + /// + /// + /// + IEnumerable GetByQuery(IQuery query); + + /// + /// Returns the count for the specified query + /// + /// + /// + int Count(IQuery query); + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs b/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs new file mode 100644 index 0000000000..b01bebdb71 --- /dev/null +++ b/src/Umbraco.Core/Persistence/Repositories/IScriptRepository.cs @@ -0,0 +1,9 @@ +using Umbraco.Core.Models; + +namespace Umbraco.Core.Persistence.Repositories +{ + public interface IScriptRepository : ISimpleRepository + { + + } +} \ No newline at end of file diff --git a/src/Umbraco.Core/Persistence/Repositories/IRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ISimpleRepository.cs similarity index 56% rename from src/Umbraco.Core/Persistence/Repositories/IRepository.cs rename to src/Umbraco.Core/Persistence/Repositories/ISimpleRepository.cs index d47ce7400c..cf29a7cc11 100644 --- a/src/Umbraco.Core/Persistence/Repositories/IRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ISimpleRepository.cs @@ -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 { - /// - /// Defines the implementation of a Repository - /// - /// Type of entity for which the repository is used - /// Type of the Id used for this entity - public interface IRepository - where TEntity : IAggregateRoot + public interface ISimpleRepository { /// /// Adds or Updates an Entity @@ -39,13 +31,6 @@ namespace Umbraco.Core.Persistence.Repositories /// IEnumerable GetAll(params TId[] ids); - /// - /// Gets all entities of the spefified type and query - /// - /// - /// - IEnumerable GetByQuery(IQuery query); - /// /// Boolean indicating whether an Entity with the specified Id exists /// @@ -53,13 +38,6 @@ namespace Umbraco.Core.Persistence.Repositories /// bool Exists(TId id); - /// - /// Returns the count for the specified query - /// - /// - /// - int Count(IQuery query); - /// /// Sets the Unit Of Work for the Repository /// diff --git a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs index 1dd7df8e90..657c2ef780 100644 --- a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs +++ b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs @@ -13,7 +13,7 @@ namespace Umbraco.Core.Persistence.Repositories /// /// Type of entity for which the repository is used /// Type of the Id used for this entity - internal abstract class RepositoryBase : IRepository, + internal abstract class RepositoryBase : IRepositoryQueryable, IUnitOfWorkRepository where TEntity : IAggregateRoot { private IUnitOfWork _work; diff --git a/src/Umbraco.Core/Persistence/RepositoryResolver.cs b/src/Umbraco.Core/Persistence/RepositoryResolver.cs index f939c0c852..b3eb4b6ef8 100644 --- a/src/Umbraco.Core/Persistence/RepositoryResolver.cs +++ b/src/Umbraco.Core/Persistence/RepositoryResolver.cs @@ -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(IUnitOfWork unitOfWork) - where TRepository : class, IRepository + where TRepository : class, IRepositoryQueryable 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))) + if (unitOfWork != null && repository.GetType().IsSubclassOf(typeof(IRepositoryQueryable))) { repository.SetUnitOfWork(unitOfWork); } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 122d0be3eb..a5ef66d7ff 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -129,8 +129,10 @@ - + + +