public void Handle(IMessage msg, string processor) { using (var resolver = _container.BeginLifetimeScope()) { var handler = InstantiateHandler(resolver); HandleMessage(msg, handler, processor); } }
public HandlerTypeInvokerTests() { _di = Substitute.For<IContainerScope>(); _err = Substitute.For<IFailedMessagesQueue>(); _di.BeginLifetimeScope().Returns(_di); _handler=new MyHandler(); _di.Resolve(typeof (MyHandler)).Returns(_handler); _sut =new HandlerTypeInvoker(typeof(MyHandler),_di,new BusAuditor(NullStorage.Instance), _err); }
public HandlerTypeInvokerTests() { _di = Substitute.For <IContainerScope>(); _err = Substitute.For <IFailedMessagesQueue>(); _di.BeginLifetimeScope().Returns(_di); _handler = new MyHandler(); _di.Resolve(typeof(MyHandler)).Returns(_handler); _sut = new HandlerTypeInvoker(typeof(MyHandler), _di, new BusAuditor(NullStorage.Instance), _err); }
private void Setup() { _di.BeginLifetimeScope().Returns(_di); _di.Resolve <IStoreSagaState>().Returns(_storage); _di.Resolve(typeof(MySagaState)).Returns(_saga); _storage.GetSaga(Arg.Any <string>(), typeof(MySagaState)).Returns(_saga); _invoker.HandlerType.Returns(typeof(Handler)); _invoker.InstantiateHandler(_di).Returns(_handler); }
public virtual void Handle(IMessage msg, string processor) { using (var scope = Container.BeginLifetimeScope()) { dynamic handler = HandlerInvoker.InstantiateHandler(scope); var correlationId = handler.GetCorrelationId(msg as IEvent); var tries = 0; while (tries < 5) { LogManager.LogDebug(this, "Loading saga {0} with correlation id {1}", SagaStateType.Name, correlationId); dynamic data = GetSagaState(msg as IEvent, scope, correlationId); if (data == null || data.IsCompleted) { this.LogInfo("Saga '{0}' completed or not found. Ignoring message '{1}'", SagaStateType.FullName, msg.GetType().FullName); return; } string stateName = data.GetType().ToString(); this.LogDebug("Handling saga '{2}' using saga state '{0}' with correlation id {1}", stateName, (string)correlationId, SagaStateType.Name); handler.Data = data; HandlerInvoker.HandleMessage(msg, handler, processor); try { SaveSagaState(data, scope, correlationId); break; } catch (SagaConcurrencyException) { tries++; this.LogInfo("Saga '{0}' was already updated. Retrying...", SagaStateType.FullName); } } if (tries >= 5) { throw new SagaExecutorException("Could no save saga state after 5 tries. Aborting."); } } }