示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Subscription"/> class.
        /// </summary>
        /// <param name="handler">The change handler.</param>
        /// <param name="filter">The MongoDB collection namespace wildcard filter.</param>
        /// <exception cref="ArgumentNullException"><paramref name="handler"/> is <see langword="null" />.</exception>
        public Subscription(IHandleChange handler, string filter)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            _reference = new WeakReference(handler);
            Filter     = filter;
        }
        /// <summary>
        /// Subscribe to change notification with the specified <paramref name="subscriber"/> and collection namespace <paramref name="filter"/>.
        /// </summary>
        /// <param name="subscriber">The change notification subscriber.</param>
        /// <param name="filter">The MongoDB collection namespace wildcard filter.</param>
        /// <returns>The subscription instance.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="subscriber"/> is <see langword="null" />.</exception>
        public ISubscription Subscribe(IHandleChange subscriber, string filter = null)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            var subscription = new Subscription(subscriber, filter);

            lock (_subscribers)
                _subscribers.Add(subscription);

            return(subscription);
        }