/// <summary> /// Specify that the service bus should load the StateMachineSagas from the container passed as argument /// </summary> /// <param name="configurator"></param> /// <param name="container"></param> public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IKernel container) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (container == null) { throw new ArgumentNullException(nameof(container)); } var registrationConfigurator = new RegistrationConfigurator(); container.Register(Component.For <ISagaStateMachineFactory>().Instance(new WindsorSagaStateMachineFactory(container))); container.Register(Component.For <IStateMachineActivityFactory>().Instance(new WindsorStateMachineActivityFactory())); container.Register(Component.For <ISagaRepositoryFactory>().Instance(new WindsorSagaRepositoryFactory(container))); IEnumerable <Type> sagaTypes = FindStateMachineSagaTypes(container); foreach (var sagaType in sagaTypes) { SagaStateMachineRegistrationCache.AddSagaStateMachine(registrationConfigurator, sagaType); } var registration = registrationConfigurator.CreateRegistration(new WindsorConfigurationServiceProvider(container)); registration.ConfigureSagas(configurator); }
/// <summary> /// Adds SagaStateMachines to the registry, using the factory method, and updates the registrar prior to registering so that the default /// saga registrar isn't notified. /// </summary> /// <param name="configurator"></param> /// <param name="registrar"></param> /// <param name="types">The state machine types to add</param> public static void AddSagaStateMachines(this IRegistrationConfigurator configurator, ISagaStateMachineRegistrar registrar, params Type[] types) { IEnumerable <Type> sagaTypes = types.Where(x => x.HasInterface(typeof(SagaStateMachine <>))); IEnumerable <Type> sagaDefinitionTypes = types.Where(x => x.HasInterface(typeof(ISagaDefinition <>))); var sagas = from c in sagaTypes join d in sagaDefinitionTypes on c.GetClosingArguments(typeof(SagaStateMachine <>)).Single() equals d.GetClosingArguments(typeof(ISagaDefinition <>)).Single() into dc from d in dc.DefaultIfEmpty() select new { SagaType = c, DefinitionType = d }; foreach (var saga in sagas) { SagaStateMachineRegistrationCache.AddSagaStateMachine(configurator, saga.SagaType, saga.DefinitionType, registrar); } }