Skip to content

Commit

Permalink
Adding project repositories base. related #1
Browse files Browse the repository at this point in the history
  • Loading branch information
andreazevedo committed Aug 8, 2011
1 parent 371c404 commit 9e72834
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/PetStore.Core/PetStore.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<Compile Include="Infrastructure\UnitOfWork\IUnitOfWork.cs" />
<Compile Include="Infrastructure\UnitOfWork\UnitOfWorkManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repository\AddPersistenceException.cs" />
<Compile Include="Repository\FindPersistenceException.cs" />
<Compile Include="Repository\IRepository.cs" />
<Compile Include="Repository\PersistenceException.cs" />
<Compile Include="Repository\RemovePersistenceException.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PetStore.Resources\PetStore.Resources.csproj">
Expand Down
42 changes: 42 additions & 0 deletions src/PetStore.Core/Repository/AddPersistenceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using PetStore.Core.Extension;
using PetStore.Resources;

namespace PetStore.Core.Repository
{
/// <summary>
/// Exception on adding objects to repositories
/// </summary>
public class AddPersistenceException : PersistenceException
{
#region Constructors

public AddPersistenceException() : this(GeneralResources.AddPersistenceExceptionDefaultMessage) { }

public AddPersistenceException(string message) : base(message) { }

public AddPersistenceException(string message, Exception innerException) : base(message, innerException) { }

protected AddPersistenceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

public AddPersistenceException(object obj, Exception innerException) : base(GetMessage(obj), innerException) { }

#endregion

#region Private Methods

private static string GetMessage(object obj)
{
return GeneralResources.AddPersistenceExceptionCustomMessage.FormatWith(obj);
}

#endregion
}
}
42 changes: 42 additions & 0 deletions src/PetStore.Core/Repository/FindPersistenceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using PetStore.Core.Extension;
using PetStore.Resources;

namespace PetStore.Core.Repository
{
/// <summary>
/// Exception on retrieving objects from repositories
/// </summary>
public class FindPersistenceException : PersistenceException
{
#region Constructors

public FindPersistenceException() : this(GeneralResources.FindPersistenceExceptionDefaultMessage) { }

public FindPersistenceException(string message) : base(message) { }

public FindPersistenceException(string message, Exception innerException) : base(message, innerException) { }

protected FindPersistenceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

public FindPersistenceException(Type entityType, long objectId, Exception innerException) : base(GetMessage(entityType, objectId), innerException) { }

#endregion

#region Private Methods

private static string GetMessage(Type entityType, long objectId)
{
return GeneralResources.FindPersistenceExceptionCustomMessage.FormatWith(objectId, entityType);
}

#endregion
}
}
36 changes: 36 additions & 0 deletions src/PetStore.Core/Repository/IRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PetStore.Core.Repository
{
/// <summary>
/// Generic repository interface
/// </summary>
/// <typeparam name="TEntity">Entity (agregation root).</typeparam>
public interface IRepository<TEntity> where TEntity : class
{
/// <summary>
/// Add (or update) an entity to the repository
/// </summary>
/// <param name="obj">Object to be added/updated.</param>
/// <exception cref="AddPersistenceException">Exception thrown when there is a problem on adding the object to the repository.</exception>
void Add(TEntity obj);

/// <summary>
/// Remove an entity from the repository
/// </summary>
/// <param name="obj">Object to be removed.</param>
/// <exception cref="RemovePersistenceException">Exception thrown when there is a problem on removing an entity from the repository.</exception>
void Remove(TEntity obj);

/// <summary>
/// Retrieves an entity.
/// </summary>
/// <param name="id">ID</param>
/// <returns>Entity</returns>
/// <exception cref="FindPersistenceException">Exception thrown when there is a problem on retrieving an entity from the repository.</exception>
TEntity FindById(int id);
}
}
39 changes: 39 additions & 0 deletions src/PetStore.Core/Repository/PersistenceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using PetStore.Resources;

namespace PetStore.Core.Repository
{
/// <summary>
/// Generic persistence exception.
/// </summary>
public abstract class PersistenceException : DomainException
{
#region Constructors

protected PersistenceException()
: this(GeneralResources.PersistenceExceptionDefaultMessage)
{
}

protected PersistenceException(string message)
: base(message)
{
}

protected PersistenceException(string message, Exception innerException)
: base(message, innerException)
{
}

protected PersistenceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

#endregion
}
}
42 changes: 42 additions & 0 deletions src/PetStore.Core/Repository/RemovePersistenceException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using PetStore.Core.Extension;
using PetStore.Resources;

namespace PetStore.Core.Repository
{
/// <summary>
/// Exception on removing objects from repositories
/// </summary>
public class RemovePersistenceException : PersistenceException
{
#region Constructors

public RemovePersistenceException() : this(GeneralResources.RemovePersistenceExceptionDefaultMessage) { }

public RemovePersistenceException(string message) : base(message) { }

public RemovePersistenceException(string message, Exception innerException) : base(message, innerException) { }

protected RemovePersistenceException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}

public RemovePersistenceException(object obj, Exception innerException) : base(GetMessage(obj), innerException) { }

#endregion

#region Private Methods

private static string GetMessage(object obj)
{
return GeneralResources.RemovePersistenceExceptionCustomMessage.FormatWith(obj);
}

#endregion
}
}
72 changes: 72 additions & 0 deletions src/PetStore.Resources/GeneralResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/PetStore.Resources/GeneralResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,40 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="AddPersistenceExceptionCustomMessage" xml:space="preserve">
<value>An error occurred while adding the object \"{0}\" to the repository.</value>
<comment>An error occurred while adding the object \"{0}\" to the repository.</comment>
</data>
<data name="AddPersistenceExceptionDefaultMessage" xml:space="preserve">
<value>An error occurred while adding the object to the repository.</value>
<comment>An error occurred while adding the object to the repository.</comment>
</data>
<data name="DomainExceptionDefaultMessage" xml:space="preserve">
<value>Domain error.</value>
<comment>Domain error.</comment>
</data>
<data name="FindPersistenceExceptionCustomMessage" xml:space="preserve">
<value>An error ocurred while retrieving the object of id \"{0}\" and type \"{1}\" from the repository.</value>
<comment>An error ocurred while retrieving the object of id \"{0}\" and type \"{1}\" from the repository.</comment>
</data>
<data name="FindPersistenceExceptionDefaultMessage" xml:space="preserve">
<value>An error occurred while retrieving the object from the repository.</value>
<comment>An error ocurred while retrieving the object from the repository.</comment>
</data>
<data name="PersistenceExceptionDefaultMessage" xml:space="preserve">
<value>An error occurred while persisting the object.</value>
<comment>An error ocurred while persisting the object.</comment>
</data>
<data name="RemovePersistenceExceptionCustomMessage" xml:space="preserve">
<value>An error occurred while removing the object \"{0}\" from the repository.</value>
<comment>An error ocurrend while removing the object \"{0}\" from the repository.</comment>
</data>
<data name="RemovePersistenceExceptionDefaultMessage" xml:space="preserve">
<value>An error occurred while removing the object from the repository.</value>
<comment>An error occurred while removing the object from the repository.</comment>
</data>
<data name="ValidationExceptionDefaultMessage" xml:space="preserve">
<value>Validation error.</value>
<comment>Validation error.</comment>
</data>
</root>

0 comments on commit 9e72834

Please sign in to comment.