public void RegisterSubscriberFor <TEvent>(SubscribesTo <TEvent> subscriber) { if (!eventSubscribers.ContainsKey(typeof(TEvent))) { eventSubscribers.Add(typeof(TEvent), new List <Action <object> >()); } eventSubscribers[typeof(TEvent)].Add(@event => subscriber.Handle((TEvent)@event)); }
public void RejectSubscription(Guid userId) { var subscription = SubscribesTo.FirstOrDefault(s => s.UserId == userId); if (subscription == null) { throw new Exception("You are not subscribe to this user"); } Subscribers.Remove(subscription); }
public void SubscribeTo(User targetUser) { if (Id == targetUser.Id) { throw new Exception("You can not add to subscribers yourself"); } if (SubscribesTo.Any(s => s.Subscriber.Id == Id)) { throw new Exception("You already have been subscribed"); } SubscribesTo.Add(new UserSubscriber(targetUser, this)); }