Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save wellingtonjhn/427bf809fd05b0703927bbdb6808f452 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/427bf809fd05b0703927bbdb6808f452 to your computer and use it in GitHub Desktop.
Domain Notification Structures Sample
public class Notification
{
public string Key { get; }
public string Message { get; }
public Notification(string key, string message)
{
Key = key;
Message = message;
}
}
public class NotificationContext
{
private readonly List<Notification> _notifications;
public IReadOnlyCollection<Notification> Notifications => _notifications;
public bool HasNotifications => _notifications.Any();
public NotificationContext()
{
_notifications = new List<Notification>();
}
public void AddNotification(string key, string message)
{
_notifications.Add(new Notification(key, message));
}
public void AddNotification(Notification notification)
{
_notifications.Add(notification);
}
public void AddNotifications(IReadOnlyCollection<Notification> notifications)
{
_notifications.AddRange(notifications);
}
public void AddNotifications(IList<Notification> notifications)
{
_notifications.AddRange(notifications);
}
public void AddNotifications(ICollection<Notification> notifications)
{
_notifications.AddRange(notifications);
}
public void AddNotifications(ValidationResult validationResult)
{
foreach (var error in validationResult.Errors)
{
AddNotification(error.ErrorCode, error.ErrorMessage);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment