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));
        }
Пример #2
0
        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);
        }
Пример #3
0
        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));
        }