Skip to content

Instantly share code, notes, and snippets.

@ar3cka
Last active August 29, 2015 14:01
Show Gist options
  • Save ar3cka/f75c96ed0fefa67d8f99 to your computer and use it in GitHub Desktop.
Save ar3cka/f75c96ed0fefa67d8f99 to your computer and use it in GitHub Desktop.
DDD, Error event design.
public abstract class DomainError : IEvent
{
public override string ToString()
{
return Describe();
}
protected abstract string Describe();
}
public class OnlineStoreNotFound : DomainError
{
public OnlineStoreNotFound(OnlineStoreId onlineStoreId)
{
OnlineStoreId = Guard.GetNotNull(onlineStoreId, "onlineStoreId");
}
public OnlineStoreId OnlineStoreId { get; private set; }
protected override string Describe()
{
return "Online store with identifier '{0}' not found.".FormatString(OnlineStoreId);
}
}
[Serializable]
public sealed class DomainException<TError> : Exception
where TError : DomainError
{
...
TError Error { get; private set; }
...
}
throw new OnlineStoreNotFound(onlineStoreId).AsDomainException();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment