protected AggregateSagaManager(Expression <Func <TAggregateSaga> > sagaFactory, bool autoSubscribe = true) { Logger = Context.GetLogger(); Context.System.EventStream.Subscribe(Self, typeof(DeadLetter)); SagaLocator = (TSagaLocator)Activator.CreateInstance(typeof(TSagaLocator)); SagaFactory = sagaFactory; Settings = new AggregateSagaManagerSettings(Context.System.Settings.Config); var sagaType = typeof(TAggregateSaga); if (autoSubscribe && Settings.AutoSubscribe) { var sagaHandlesSubscriptionTypes = sagaType .GetSagaEventSubscriptionTypes(); foreach (var type in sagaHandlesSubscriptionTypes) { Context.System.EventStream.Subscribe(Self, type); } } if (Settings.AutoSpawnOnReceive) { ReceiveAsync <IDomainEvent>(Handle); } }
protected AggregateSagaManager(Expression <Func <TAggregateSaga> > sagaFactory) { Logger = Context.GetLogger(); _subscriptionTypes = new List <Type>(); SagaLocator = new TSagaLocator(); SagaFactory = sagaFactory; Settings = new AggregateSagaManagerSettings(Context.System.Settings.Config); var sagaType = typeof(TAggregateSaga); if (Settings.AutoSubscribe) { var sagaEventSubscriptionTypes = sagaType .GetSagaEventSubscriptionTypes(); var asyncSagaEventSubscriptionTypes = sagaType .GetAsyncSagaEventSubscriptionTypes(); var subscriptionTypes = new List <Type>(); subscriptionTypes.AddRange(sagaEventSubscriptionTypes); subscriptionTypes.AddRange(asyncSagaEventSubscriptionTypes); _subscriptionTypes = subscriptionTypes.AsReadOnly(); foreach (var type in _subscriptionTypes) { Context.System.EventStream.Subscribe(Self, type); } } if (Settings.AutoSpawnOnReceive) { Receive <IDomainEvent>(Handle); } Receive <UnsubscribeFromAll>(Handle); Receive <Terminated>(Terminate); }