public EventDispatcher(ReadModelDbContext dbContext, ILogger logger) { _dbContext = dbContext; _logger = logger; _resolver = new EventHandlerResolver(); RegisterHandlers(); }
static ReallySimpleEventing() { EventHandlerResolver = new EventHandlerResolver(); ActivationStrategy = new ActivatorActivation(); ThreadingStrategies = new List<IHandlerThreadingStrategy> // Order is important for selection { new TaskOfT(), new CurrentThread() // Default }; }
/// <summary> /// Publishes the provided <paramref name="event"/> on the event bus. /// </summary> public virtual void Publish <TEvent>(TEvent @event) where TEvent : IEvent <TAuthenticationToken> { // We only set these two properties as they are not going to be available across the thread/task if (@event.AuthenticationToken == null || @event.AuthenticationToken.Equals(default(TAuthenticationToken))) { @event.AuthenticationToken = AuthenticationTokenHelper.GetAuthenticationToken(); } @event.CorrelationId = CorrelationIdHelper.GetCorrelationId(); bool result = EventHandlerResolver.Ask <bool>(@event).Result; }
public static EventHandlerDispatcher Using(EventHandlerResolver resolver) { if (resolver == null) { throw new ArgumentNullException(nameof(resolver)); } return((message, cancellationToken) => { var handlers = resolver(message); return Task.WhenAll(handlers.Select(handler => handler(message, cancellationToken))); }); }
/// <summary> /// Passes the provided <paramref name="event"/> to <see cref="EventHandlerResolver"/> via <see cref="IEventPublisher{TAuthenticationToken}.Publish{TEvent}(TEvent)"/> /// then calls <see cref="ActorRefImplicitSenderExtensions.Tell"/>. /// </summary> protected virtual void ExecuteReceive(IEvent <TAuthenticationToken> @event) { try { AuthenticationTokenHelper.SetAuthenticationToken(@event.AuthenticationToken); CorrelationIdHelper.SetCorrelationId(@event.CorrelationId); EventHandlerResolver.Publish(@event); Sender.Tell(true); } catch { Sender.Tell(false); throw; } }
public Daemon() { _state = new State(); _resolver = new EventHandlerResolver(); }