Consider the following piece of code:
public class Article : AbstractEntity<Article> {
// ...
public void AppendFeedback(Feedback feedback) {
var quota = this.FeedbacksQuota ?? this.DefaultFeedbacksQuota;
if(this.Feedbacks.Count >= quota) {
throw new ApplicationException("message");
}
this.Feedbacks.Add(feedback);
}
// ...
}
So I don’t know how would I notify users when quota gets exceeded. Throwing an exception seems bad to me. Is it the right place to use domain events? (Examples are appreciated, especially in context of ASP.NET MVC application).
Where should I gather/handle the messaging?
Thanks!
If your feedback quota is an invariant (business rule) then an exception is fine.
You can always add a method such as:
To check whether feedback is allowed before adding so that you can return a meaningful/user friendly message.
You could raise a domain event on feedback added that contains the quota left, etc.