Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="EventContext"/> with the specified <paramref name="aggregateId"/> and <paramref name="headers"/>.
        /// </summary>
        /// <param name="aggregateId">The unique <see cref="Aggregate"/> identifier.</param>
        /// <param name="headers">The <see cref="Event"/> headers.</param>
        /// <param name="e">The <see cref="Event"/>.</param>
        public EventContext(Guid aggregateId, HeaderCollection headers, Event e)
        {
            Verify.NotEqual(Guid.Empty, aggregateId, nameof(aggregateId));
            Verify.NotNull(headers, nameof(headers));
            Verify.NotNull(e, nameof(e));

            this.originalContext = currentContext;
            this.thread = Thread.CurrentThread;
            this.aggregateId = aggregateId;
            this.headers = headers;
            this.@event = e;

            currentContext = this;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Releases all managed resources used by the current instance of the <see cref="EventContext"/> class.
        /// </summary>
        public void Dispose()
        {
            if (disposed)
                return;

            if (thread != Thread.CurrentThread)
                throw new InvalidOperationException(Exceptions.EventContextInterleaved);

            if (this != Current)
                throw new InvalidOperationException(Exceptions.EventContextInvalidThread);

            disposed = true;
            currentContext = originalContext;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Invokes the underlying <see cref="Object"/> event handler method using the specified <paramref name="context"/>.
        /// </summary>
        /// <param name="context">The current event context.</param>
        public virtual void Handle(EventContext context)
        {
            Verify.NotNull(context, nameof(context));

            Log.Trace("{0} handling event {0}", handlerType, context.Event);

            Executor.Invoke(eventHandlerFactory(), context.Event);
        }