public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector bus, SagaStateMachine <TInstance> stateMachine, IContainer container) where TInstance : class, SagaStateMachineInstance { var connector = new StateMachineConnector <TInstance>(stateMachine); ISagaRepositoryFactory repositoryFactory = new LamarStateMachineSagaRepositoryFactory(container); ISagaRepository <TInstance> sagaRepository = repositoryFactory.CreateSagaRepository <TInstance>(); ISagaSpecification <TInstance> specification = connector.CreateSagaSpecification <TInstance>(); return(connector.ConnectSaga(bus, sagaRepository, specification)); }
public static ConnectHandle ConnectStateMachineSaga <TInstance>(this IConsumePipeConnector bus, SagaStateMachine <TInstance> stateMachine, ILifetimeScope scope, string name = "message", Action <ContainerBuilder, ConsumeContext> configureScope = null) where TInstance : class, SagaStateMachineInstance { var connector = new StateMachineConnector <TInstance>(stateMachine); ISagaRepositoryFactory repositoryFactory = new AutofacStateMachineSagaRepositoryFactory(new SingleLifetimeScopeProvider(scope), name, configureScope); ISagaRepository <TInstance> sagaRepository = repositoryFactory.CreateSagaRepository <TInstance>(); ISagaSpecification <TInstance> specification = connector.CreateSagaSpecification <TInstance>(); return(connector.ConnectSaga(bus, sagaRepository, specification)); }
/// <summary> /// Connects the saga to the bus /// </summary> /// <typeparam name="T">The saga type</typeparam> /// <param name="connector">The bus to which the saga is to be connected</param> /// <param name="sagaRepository">The saga repository</param> /// <param name="pipeSpecifications"></param> public static ConnectHandle ConnectSaga <T>(this IConsumePipeConnector connector, ISagaRepository <T> sagaRepository, params IPipeSpecification <SagaConsumeContext <T> >[] pipeSpecifications) where T : class, ISaga { if (connector == null) { throw new ArgumentNullException(nameof(connector)); } if (sagaRepository == null) { throw new ArgumentNullException(nameof(sagaRepository)); } LogContext.Debug?.Log("Connecting Saga: {SagaType}", TypeMetadataCache <T> .ShortName); ISagaSpecification <T> specification = SagaConnectorCache <T> .Connector.CreateSagaSpecification <T>(); foreach (IPipeSpecification <SagaConsumeContext <T> > pipeSpecification in pipeSpecifications) { specification.AddPipeSpecification(pipeSpecification); } return(SagaConnectorCache <T> .Connector.ConnectSaga(connector, sagaRepository, specification)); }
public ConnectHandle ConnectSaga <T>(IConsumePipeConnector consumePipe, ISagaRepository <T> sagaRepository, ISagaSpecification <T> specification) where T : class, ISaga { var handles = new List <ConnectHandle>(); try { foreach (ISagaMessageConnector <T> connector in _connectors.Cast <ISagaMessageConnector <T> >()) { var handle = connector.ConnectSaga(consumePipe, sagaRepository, specification); handles.Add(handle); } return(new MultipleConnectHandle(handles)); } catch (Exception) { foreach (var handle in handles) { handle.Dispose(); } throw; } }
public ConnectHandle ConnectSaga(IConsumePipeConnector consumePipe, ISagaRepository <TSaga> repository, ISagaSpecification <TSaga> specification) { ISagaMessageSpecification <TSaga, TMessage> messageSpecification = specification.GetMessageSpecification <TMessage>(); IPipe <SagaConsumeContext <TSaga, TMessage> > consumerPipe = messageSpecification.BuildConsumerPipe(_consumeFilter); IPipe <ConsumeContext <TMessage> > messagePipe = messageSpecification.BuildMessagePipe(x => { ConfigureMessagePipe(x, repository, consumerPipe); }); return(consumePipe.ConnectConsumePipe(messagePipe)); }