ISagaRepository <T> ISagaRepositoryFactory.CreateSagaRepository <T>()
        {
            var repository = _scopeProvider.LifetimeScope.Resolve <ISagaRepository <T> >();

            var scopeProvider = new AutofacSagaScopeProvider <T>(_scopeProvider, _name);

            scopeProvider.AddScopeAction(x => x.GetOrAddPayload <IStateMachineActivityFactory>(() => new AutofacStateMachineActivityFactory()));

            return(new ScopeSagaRepository <T>(repository, scopeProvider));
        }
예제 #2
0
        /// <summary>
        /// Registers a saga using the container that has the repository resolved from the container
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="scope"></param>
        /// <param name="configure"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static void Saga <T>(this IReceiveEndpointConfigurator configurator, ILifetimeScope scope, Action <ISagaConfigurator <T> > configure, string name = "message")
            where T : class, ISaga
        {
            var repository = scope.Resolve <ISagaRepository <T> >();

            ISagaScopeProvider <T> scopeProvider = new AutofacSagaScopeProvider <T>(new SingleLifetimeScopeProvider(scope), name);

            var sagaRepository = new ScopeSagaRepository <T>(repository, scopeProvider);

            configurator.Saga(sagaRepository, configure);
        }
예제 #3
0
        ISagaRepository <T> ISagaRepositoryFactory.CreateSagaRepository <T>(Action <ConsumeContext> scopeAction)
        {
            var repository = _scopeProvider.LifetimeScope.Resolve <ISagaRepository <T> >();

            var scopeProvider = new AutofacSagaScopeProvider <T>(_scopeProvider, _name, _configureScope);

            if (scopeAction != null)
            {
                scopeProvider.AddScopeAction(scopeAction);
            }

            return(new ScopeSagaRepository <T>(repository, scopeProvider));
        }
예제 #4
0
        /// <summary>
        /// Registers a saga using the container that has the repository resolved from the container
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configurator"></param>
        /// <param name="context"></param>
        /// <param name="configure"></param>
        /// <param name="name"></param>
        /// <param name="configureScope">Configuration for scope container</param>
        /// <returns></returns>
        public static void Saga <T>(this IReceiveEndpointConfigurator configurator, IComponentContext context, Action <ISagaConfigurator <T> > configure, string name = "message",
                                    Action <ContainerBuilder, ConsumeContext> configureScope = null)
            where T : class, ISaga
        {
            var scope = context.Resolve <ILifetimeScope>();

            var repository = scope.Resolve <ISagaRepository <T> >();

            ISagaScopeProvider <T> scopeProvider = new AutofacSagaScopeProvider <T>(new SingleLifetimeScopeProvider(scope), name, configureScope);

            var sagaRepository = new ScopeSagaRepository <T>(repository, scopeProvider);

            configurator.Saga(sagaRepository, configure);
        }