public void Configure(IReceiveEndpointConfigurator configurator, IConfigurationServiceProvider configurationServiceProvider) { ISagaStateMachineFactory stateMachineFactory = configurationServiceProvider.GetRequiredService <ISagaStateMachineFactory>(); SagaStateMachine <TInstance> stateMachine = stateMachineFactory.CreateStateMachine <TInstance>(); IStateMachineActivityFactory activityFactory = configurationServiceProvider.GetRequiredService <IStateMachineActivityFactory>(); void AddStateMachineActivityFactory(ConsumeContext context) { context.GetOrAddPayload(() => activityFactory); } var repositoryFactory = configurationServiceProvider.GetRequiredService <ISagaRepositoryFactory>(); ISagaRepository <TInstance> repository = repositoryFactory.CreateSagaRepository <TInstance>(AddStateMachineActivityFactory); var stateMachineConfigurator = new StateMachineSagaConfigurator <TInstance>(stateMachine, repository, configurator); GetSagaDefinition(configurationServiceProvider) .Configure(configurator, stateMachineConfigurator); foreach (Action <ISagaConfigurator <TInstance> > action in _configureActions) { action(stateMachineConfigurator); } configurator.AddEndpointSpecification(stateMachineConfigurator); }
public WindsorSagaScopeProvider(IKernel kernel) { _kernel = kernel; _scopeActions = new List <Action <ConsumeContext> >(); _factory = new WindsorStateMachineActivityFactory(); }
public ImageRetrievalStateMachine(IStateMachineActivityFactory activityFactory) { _activityFactory = activityFactory; State(() => Pending); State(() => Available); State(() => Faulted); Event(() => Requested); Event(() => Retrieved); Event(() => RetrieveFailed); Event(() => NotFound); Initially( When(Requested) .Then((state, message) => { _log.DebugFormat("Requested: {0} ({1})", message.SourceAddress, message.RequestId); state.Created = DateTime.UtcNow; state.FirstRequested = message.Timestamp; state.SourceAddress = message.SourceAddress; state.LocalAddress = new Uri("urn:unknown"); }) .Then(() => _activityFactory.GetActivity <SendRetrieveImageCommandActivity, ImageRetrievalState>()) .Publish((_, message) => new ImageRequestedEvent(message.RequestId, message.SourceAddress)) .TransitionTo(Pending)); During(Pending, // this is to handle the contract of publishing the event but an existing request is // already pending When(Requested) .Then( (state, message) => { _log.DebugFormat("Pending: {0} ({1})", state.SourceAddress, message.RequestId); }) .Publish((_, message) => new ImageRequestedEvent(message.RequestId, message.SourceAddress)), // this event is observed when the service completes the image retrieval When(Retrieved) .Then((state, message) => { _log.DebugFormat("Retrieved: {0} ({1})", message.LocalAddress, state.CorrelationId); state.LastRetrieved = message.Timestamp; state.LocalAddress = message.LocalAddress; state.ContentType = message.ContentType; state.ContentLength = message.ContentLength; }) .TransitionTo(Available), When(RetrieveFailed) .Then((state, message) => state.Reason = message.Reason) .TransitionTo(Faulted) .Publish((_, message) => new ImageRequestFaultedEvent(message.SourceAddress, message.Reason)) ); During(Available, When(Requested) .Then((state, message) => { _log.DebugFormat("Available: {0} {2} ({1})", state.LocalAddress, message.RequestId, state.SourceAddress); }) .Publish((_, message) => new ImageRequestedEvent(message.RequestId, message.SourceAddress)) .Respond((state, message) => new ImageRequestCompletedEvent(state.ContentLength.Value, state.ContentType, state.LocalAddress, state.SourceAddress, state.LastRetrieved.Value))); }
public static void Configure(Type sagaType, IReceiveEndpointConfigurator configurator, ISagaStateMachineFactory sagaStateMachineFactory, ISagaRepositoryFactory repositoryFactory, IStateMachineActivityFactory activityFactory) { GetOrAdd(sagaType).Configure(configurator, sagaStateMachineFactory, repositoryFactory, activityFactory); }