/// <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> /// Scans the lifetime scope and registers any state machines sagas which are found in the scope using the StructureMap saga repository /// and the appropriate state machine saga repository under the hood. /// </summary> /// <param name="configurator"></param> /// <param name="container"></param> public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IContainer container) { var registrationConfigurator = new RegistrationConfigurator(); container.Configure(x => { if (container.TryGetInstance <ISagaStateMachineFactory>() == null) { x.AddSingleton <ISagaStateMachineFactory>(provider => new LamarSagaStateMachineFactory(provider)); } if (container.TryGetInstance <ISagaRepositoryFactory>() == null) { x.AddSingleton <ISagaRepositoryFactory>(provider => new LamarSagaRepositoryFactory(container)); } if (container.TryGetInstance <IStateMachineActivityFactory>() == null) { x.AddSingleton <IStateMachineActivityFactory>(provider => new LamarStateMachineActivityFactory()); } }); registrationConfigurator.AddSagaStateMachines(new NullSagaStateMachineRegistrar(), FindStateMachineSagaTypes(container)); var registration = registrationConfigurator.CreateRegistration(new LamarConfigurationServiceProvider(container)); registration.ConfigureSagas(configurator); }
/// <summary> /// Scans the lifetime scope and registers any state machines sagas which are found in the scope using the StructureMap saga repository /// and the appropriate state machine saga repository under the hood. /// </summary> /// <param name="configurator"></param> /// <param name="container"></param> public static void LoadStateMachineSagas(this IReceiveEndpointConfigurator configurator, IContainer container) { var registrationConfigurator = new RegistrationConfigurator(); container.Configure(x => { if (container.TryGetInstance <ISagaStateMachineFactory>() == null) { x.For <ISagaStateMachineFactory>().Use(provider => new StructureMapSagaStateMachineFactory(container)).Singleton(); } if (container.TryGetInstance <ISagaRepositoryFactory>() == null) { x.For <ISagaRepositoryFactory>().Use(provider => new StructureMapSagaRepositoryFactory(container)).Singleton(); } if (container.TryGetInstance <IStateMachineActivityFactory>() == null) { x.For <IStateMachineActivityFactory>().Use(provider => new StructureMapStateMachineActivityFactory()).ContainerScoped(); } }); registrationConfigurator.AddSagaStateMachines(FindStateMachineSagaTypes(container)); var registration = registrationConfigurator.CreateRegistration(new StructureMapConfigurationServiceProvider(container)); registration.ConfigureSagas(configurator); }
public static void ApplyIf(this RegistrationConfigurator configurator, bool b, Action <RegistrationConfigurator> scopeConfig) { if (b) { scopeConfig.Invoke(configurator); } }
/// <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, Container container) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (container == null) { throw new ArgumentNullException(nameof(container)); } var registrationConfigurator = new RegistrationConfigurator(); container.RegisterInstance <ISagaStateMachineFactory>(new SimpleInjectorSagaStateMachineFactory(container)); container.RegisterInstance <IStateMachineActivityFactory>(new SimpleInjectorStateMachineActivityFactory()); container.RegisterInstance <ISagaRepositoryFactory>(new SimpleInjectorSagaRepositoryFactory(container)); IEnumerable <Type> sagaTypes = FindStateMachineSagaTypes(container); foreach (var sagaType in sagaTypes) { ((IRegistrationConfigurator)registrationConfigurator).AddSagaStateMachine(sagaType); } var registration = registrationConfigurator.CreateRegistration(new SimpleInjectorConfigurationServiceProvider(container)); registration.ConfigureSagas(configurator); }
/// <inheritdoc /> public IStashboxContainer ReMap <TFrom, TTo>(Action <RegistrationConfigurator <TFrom, TTo> > configurator = null) where TFrom : class where TTo : class, TFrom { this.ThrowIfDisposed(); var registrationConfigurator = new RegistrationConfigurator <TFrom, TTo>(typeof(TFrom), typeof(TTo)); configurator?.Invoke(registrationConfigurator); return(this.ReMapInternal(registrationConfigurator)); }
/// <inheritdoc /> public IStashboxContainer Register <TTo>(Action <RegistrationConfigurator <TTo, TTo> > configurator = null) where TTo : class { this.ThrowIfDisposed(); var type = typeof(TTo); var registrationConfigurator = new RegistrationConfigurator <TTo, TTo>(type, type); configurator?.Invoke(registrationConfigurator); if (!registrationConfigurator.ImplementationIsResolvable(out var error)) { throw new InvalidRegistrationException(registrationConfigurator.ImplementationType, error); } return(this.RegisterInternal(registrationConfigurator)); }
/// <inheritdoc /> public IStashboxContainer Register(Type typeFrom, Type typeTo, Action <RegistrationConfigurator> configurator = null) { this.ThrowIfDisposed(); Shield.EnsureNotNull(typeFrom, nameof(typeFrom)); Shield.EnsureNotNull(typeTo, nameof(typeTo)); var registrationConfigurator = new RegistrationConfigurator(typeFrom, typeTo); configurator?.Invoke(registrationConfigurator); if (!registrationConfigurator.TypeMapIsValid(out var error)) { throw new InvalidRegistrationException(registrationConfigurator.ImplementationType, error); } return(this.RegisterInternal(registrationConfigurator)); }