Skip to content

Instantly share code, notes, and snippets.

@alexeyzimarev
Last active March 18, 2016 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexeyzimarev/e1c4b2041e6ee30f99fa to your computer and use it in GitHub Desktop.
Save alexeyzimarev/e1c4b2041e6ee30f99fa to your computer and use it in GitHub Desktop.
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