Beispiel #1
0
        /// <summary>
        /// Adds Twino connector with configuration
        /// </summary>
        public static IServiceCollection AddTwinoBus(this IServiceCollection services, Action <TwinoConnectorBuilder> config)
        {
            TwinoConnectorBuilder builder = new TwinoConnectorBuilder(services);

            config(builder);

            TmqStickyConnector connector = builder.Build();

            AddConsumersMicrosoftDI(services, connector, builder);
            services.AddSingleton(connector);
            services.AddSingleton(connector.Bus);
            services.AddSingleton(connector.Bus.Direct);
            services.AddSingleton(connector.Bus.Queue);
            services.AddSingleton(connector.Bus.Route);

            return(services);
        }
Beispiel #2
0
        /// <summary>
        /// Adds Twino connector with configuration
        /// </summary>
        public static IServiceCollection AddTwinoBus <TIdentifier>(this IServiceCollection services, Action <TwinoConnectorBuilder> config)
        {
            TwinoConnectorBuilder builder = new TwinoConnectorBuilder(services);

            config(builder);

            TmqStickyConnector <TIdentifier> connector = builder.Build <TIdentifier>();

            AddConsumersMicrosoftDI(services, connector, builder);
            services.AddSingleton(connector);

            TwinoBus <TIdentifier> bus = (TwinoBus <TIdentifier>)connector.Bus;

            services.AddSingleton <ITwinoBus <TIdentifier> >(bus);
            services.AddSingleton <ITwinoDirectBus <TIdentifier> >((TwinoDirectBus <TIdentifier>)bus.Direct);
            services.AddSingleton <ITwinoQueueBus <TIdentifier> >((TwinoQueueBus <TIdentifier>)bus.Queue);
            services.AddSingleton <ITwinoRouteBus <TIdentifier> >((TwinoRouteBus <TIdentifier>)bus.Route);

            return(services);
        }
Beispiel #3
0
        private static void AddConsumersTwino(ITwinoServiceCollection services, TmqStickyConnector connector, TwinoConnectorBuilder builder)
        {
            foreach (Tuple <ImplementationType, Type> pair in builder.AssembyConsumers)
            {
                IEnumerable <Type> types = connector.Observer
                                           .RegisterAssemblyConsumers(() => new TwinoIocConsumerFactory((IServiceContainer)services, pair.Item1),
                                                                      pair.Item2);

                foreach (Type type in types)
                {
                    AddConsumerIntoContainer(services, pair.Item1, type);
                }
            }

            foreach (Tuple <ImplementationType, Type> pair in builder.IndividualConsumers)
            {
                connector.Observer.RegisterConsumer(pair.Item2,
                                                    () => new TwinoIocConsumerFactory((IServiceContainer)services, pair.Item1));
                AddConsumerIntoContainer(services, pair.Item1, pair.Item2);
            }
        }
Beispiel #4
0
        private static void AddConsumersMicrosoftDI(IServiceCollection services, TmqStickyConnector connector, TwinoConnectorBuilder builder)
        {
            foreach (Tuple <ImplementationType, Type> pair in builder.AssembyConsumers)
            {
                IEnumerable <Type> types = connector.Observer
                                           .RegisterAssemblyConsumers(() => new MicrosoftDependencyConsumerFactory(pair.Item1.ToLifeTime()),
                                                                      pair.Item2);

                foreach (Type type in types)
                {
                    AddConsumerIntoCollection(services, pair.Item1, type);
                }
            }

            foreach (Tuple <ImplementationType, Type> pair in builder.IndividualConsumers)
            {
                connector.Observer.RegisterConsumer(pair.Item2, () => new MicrosoftDependencyConsumerFactory(pair.Item1.ToLifeTime()));
                AddConsumerIntoCollection(services, pair.Item1, pair.Item2);
            }
        }