/// <summary> /// Subscribe a state machine saga to the endpoint using factories to resolve the required components /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <param name="configurator"></param> /// <param name="stateMachine"></param> /// <param name="repositoryFactory"></param> /// <param name="configure">Optionally configure the saga</param> /// <returns></returns> public static void StateMachineSaga<TInstance>(this IReceiveEndpointConfigurator configurator, SagaStateMachine<TInstance> stateMachine, ISagaRepositoryFactory repositoryFactory, Action<ISagaConfigurator<TInstance>> configure = null) where TInstance : class, SagaStateMachineInstance { var repository = repositoryFactory.CreateSagaRepository<TInstance>(); StateMachineSaga(configurator, stateMachine, repository, configure); }
public static ConnectHandle ConnectStateMachineSaga<TInstance>(this IConsumePipeConnector bus, SagaStateMachine<TInstance> stateMachine, ISagaRepositoryFactory repositoryFactory, Action<ISagaConfigurator<TInstance>> configure = null) where TInstance : class, SagaStateMachineInstance { var repository = repositoryFactory.CreateSagaRepository<TInstance>(); return ConnectStateMachineSaga(bus, stateMachine, repository, configure); }
public static void Configure(Type sagaType, IReceiveEndpointConfigurator configurator, ISagaRepositoryFactory factory) { GetOrAdd(sagaType).Configure(configurator, factory); }
public static void Configure(Type sagaType, IReceiveEndpointConfigurator configurator, ISagaStateMachineFactory sagaStateMachineFactory, ISagaRepositoryFactory repositoryFactory) { GetOrAdd(sagaType).Configure(configurator, sagaStateMachineFactory, repositoryFactory); }
public static Task RegisterStateMachine(this IRabbitMqBusFactoryConfigurator bus, IRabbitMqHost host, IServiceProvider container, Type stateMachineType, ISagaRepositoryFactory repositoryFactory, Action <IRabbitMqReceiveEndpointConfigurator> configure) { bus.ReceiveEndpoint(host, stateMachineType.FullName, e => { var instanceType = stateMachineType .GetTypeInfo() .BaseType .GetGenericArguments()[0]; var createMethod = repositoryFactory .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "Create") .Where(mi => mi.IsGenericMethod) .Where(mi => mi.GetGenericArguments().Length == 1) .Single() .MakeGenericMethod(instanceType); var automatonymousIntegrationAssembly = Assembly.Load(new AssemblyName("MassTransit.AutomatonymousIntegration")); var stateMachineSagaMethod = automatonymousIntegrationAssembly .GetTypes() .Where(t => t.GetTypeInfo().IsSealed&& !t.GetTypeInfo().IsGenericType&& !t.IsNested) .SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.Public)) .Where(m => m.IsDefined(typeof(ExtensionAttribute), false) && m.GetParameters()[0].ParameterType == typeof(IReceiveEndpointConfigurator)) .Single(m => m.Name == "StateMachineSaga") .MakeGenericMethod(instanceType); var stateMachine = container.GetService(stateMachineType); var repository = createMethod.Invoke(repositoryFactory, new object[] { }); stateMachineSagaMethod.Invoke(e, new object[] { e, stateMachine, repository, null }); configure(e); }); return(Task.CompletedTask); }
public static Task RegisterStateMachines(this IRabbitMqBusFactoryConfigurator bus, IRabbitMqHost host, IServiceProvider container, ISagaRepositoryFactory repositoryFactory, Action <IRabbitMqReceiveEndpointConfigurator> configure, params Assembly[] assemblies) { if (assemblies is null || assemblies.Length == 0) { assemblies = new Assembly[] { Assembly.GetEntryAssembly() }; } var stateMachines = assemblies.SelectMany(a => a.GetTypes()).Where(t => t.GetInterfaces().Any(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == typeof(StateMachine <>))); foreach (var t in stateMachines) { bus.RegisterStateMachine(host, container, t, repositoryFactory, configure); } return(Task.CompletedTask); }
public static Task RegisterStateMachine <TStateMachine>(this IRabbitMqBusFactoryConfigurator bus, IRabbitMqHost host, IServiceProvider container, ISagaRepositoryFactory repositoryFactory, Action <IRabbitMqReceiveEndpointConfigurator> configure) where TStateMachine : class, StateMachine { return(bus.RegisterStateMachine(host, container, typeof(TStateMachine), repositoryFactory, configure)); }