Last active
August 29, 2015 14:01
-
-
Save ar3cka/f75c96ed0fefa67d8f99 to your computer and use it in GitHub Desktop.
DDD, Error event design.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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