public static ILifetimeScope GetLifetimeScope <TMessage, TId>(this ILifetimeScopeRegistry <TId> registry, ConsumeContext <TMessage> context)
            where TMessage : class
        {
            var scopeId = GetScopeId(registry, context);

            return(registry.GetLifetimeScope(scopeId));
        }
        public AutofacScopeSagaRepository(ISagaRepository <TSaga> repository, ILifetimeScopeRegistry <TId> registry, string name,
                                          Action <ContainerBuilder, ConsumeContext> configureScope)
        {
            ISagaScopeProvider <TSaga> scopeProvider =
                new AutofacSagaScopeProvider <TSaga>(new RegistryLifetimeScopeProvider <TId>(registry), name, configureScope);

            _repository = new ScopeSagaRepository <TSaga>(repository, scopeProvider);
        }
        /// <summary>
        /// Registers a consumer given the lifetime scope specified
        /// </summary>
        /// <typeparam name="T">The consumer type</typeparam>
        /// <typeparam name="TId"></typeparam>
        /// <param name="configurator">The service bus configurator</param>
        /// <param name="context">The component context containing the registry</param>
        /// <param name="name">The name of the scope created per-message</param>
        /// <returns></returns>
        public static void ConsumerInScope <T, TId>(this IReceiveEndpointConfigurator configurator, IComponentContext context, string name = "message")
            where T : class, IConsumer
        {
            ILifetimeScopeRegistry <TId> registry = context.Resolve <ILifetimeScopeRegistry <TId> >();

            IConsumerScopeProvider scopeProvider = new AutofacConsumerScopeProvider(new RegistryLifetimeScopeProvider <TId>(registry), name);

            var consumerFactory = new ScopeConsumerFactory <T>(scopeProvider);

            configurator.Consumer(consumerFactory);
        }
Exemple #4
0
        public static TId GetScopeId <TMessage, TId>(this ILifetimeScopeRegistry <TId> registry, ConsumeContext <TMessage> context)
            where TMessage : class
        {
            var scopeId = default(TId);

            // first, try to use the message-based scopeId provider
            if (registry.TryResolve(out ILifetimeScopeIdAccessor <TMessage, TId> provider) && provider.TryGetScopeId(context.Message, out scopeId))
            {
                return(scopeId);
            }

            // second, try to use the consume context based message version
            var idProvider = registry.ResolveOptional <ILifetimeScopeIdProvider <TId> >(TypedParameter.From(context), TypedParameter.From <ConsumeContext>(context));

            if (idProvider != null && idProvider.TryGetScopeId(out scopeId))
            {
                return(scopeId);
            }

            // okay, give up, default it is
            return(scopeId);
        }
 public AutofacScopeSagaRepository(ISagaRepository <TSaga> repository, ILifetimeScopeRegistry <TId> registry, string name)
 {
     _repository = repository;
     _registry   = registry;
     _name       = name;
 }
 public AutofacScopeConsumerFactory(ILifetimeScopeRegistry <TId> registry, string name)
 {
     _registry = registry;
     _name     = name;
 }
Exemple #7
0
 public RegistryLifetimeScopeProvider(ILifetimeScopeRegistry <TId> registry)
 {
     _registry = registry;
 }
 public AutofacScopeConsumerFactory(ILifetimeScopeRegistry <TId> registry, string name, Action <ContainerBuilder, ConsumeContext> configureScope)
 {
     _registry       = registry;
     _name           = name;
     _configureScope = configureScope;
 }
Exemple #9
0
        public AutofacScopeSagaRepository(ISagaRepository <TSaga> repository, ILifetimeScopeRegistry <TId> registry, string name)
        {
            ISagaScopeProvider <TSaga> scopeProvider = new AutofacSagaScopeProvider <TSaga>(new RegistryLifetimeScopeProvider <TId>(registry), name);

            _repository = new ScopeSagaRepository <TSaga>(repository, scopeProvider);
        }