Last active
March 18, 2016 12:26
-
-
Save alexeyzimarev/e1c4b2041e6ee30f99fa to your computer and use it in GitHub Desktop.
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 class Subscription | |
{ | |
public Subscription(SubscriptionId id, int maxSubscriptions) | |
{ | |
... | |
Dispatch(new SubscriptionCreated(..., maxSubscriptions)); | |
} | |
... | |
private IList<SubscriptionUser> _users; | |
private int _maxSubscriptions; | |
public void AddUser(string userId, string name) | |
{ | |
if (_users.Count() >= _maxSubscriptions) | |
throw new InvalidOperationException("Maximum number of users reached, cannot add more"); | |
Dispatch(new SubscriptionUserAdded(...)); | |
} | |
private void When(SubscriptionCreated @event) | |
{ | |
... | |
_users = new List<SubscriptionUser>(); | |
_maxSubscriptions = maxSubscriptions; | |
... | |
} | |
private void When(SubscriptionUserAdded @event) | |
{ | |
var user = new SubscriptionUser(...); | |
_users.Add(user); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment