public void Handle(StatusCodeChecked msg, IEventsDispatcher eventsDispatcher) { Debug.WriteLine($"SeleniumService: handling StatusCodeChecked({msg.ResourceId})"); var publishActions = new List <Action>(); //будем копить отправку событий // Обрабатываем сообщение в транзакции _repositoryFactory.Execute(repository => { try { string html = "some html generated by web driver"; int pageSourceId = repository.CreatePageSource(msg.ResourceId, html); var pageSourceCreated = new PageSourceCreated(pageSourceId); publishActions.Add(() => eventsDispatcher.Publish(pageSourceCreated)); repository.Commit(); } catch { repository.Rollback(); throw; } }); // Работа выполнена, транзакция закоммичена, посылаем события publishActions.ForEach(action => action()); }
public void Publish(PageSourceCreated msg) { _pageSourceCreated?.Invoke(this, msg); }