public CommandProcessorBuildDefaultInboxSendTests()
        {
            var subscriberRegistry = new SubscriberRegistry();

            //This handler has no Inbox attribute
            subscriberRegistry.Add(typeof(MyCommand), typeof(MyCommandHandler));

            var container = new ServiceCollection();

            container.AddTransient <MyCommandHandler>();
            container.AddSingleton <IAmAnInboxSync, InMemoryInbox>();
            container.AddTransient <UseInboxHandler <MyCommand> >();
            container.AddSingleton <IBrighterOptions>(new BrighterOptions()
            {
                HandlerLifetime = ServiceLifetime.Transient
            });


            _provider = container.BuildServiceProvider();
            var handlerFactory = new ServiceProviderHandlerFactory(_provider);

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .Retry();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(1));

            var inboxConfiguration = new InboxConfiguration(
                InboxScope.All,                      //grab all the events
                onceOnly: true,                      //only allow once
                actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should  be the only entry after)
                );

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            },
                inboxConfiguration: inboxConfiguration
                );

            PipelineBuilder <MyCommand> .ClearPipelineCache();
        }
コード例 #2
0
        public CommandProcessorBuildDefaultInboxPublishTests()
        {
            var handler = new MyGlobalInboxEventHandler(new Dictionary <string, Guid>());

            var subscriberRegistry = new SubscriberRegistry();

            //This handler has no Inbox attribute
            subscriberRegistry.Add(typeof(MyEvent), typeof(MyGlobalInboxEventHandler));

            var container = new ServiceCollection();

            container.AddSingleton <MyGlobalInboxEventHandler>(handler);
            container.AddSingleton <IAmAnInbox>(_inbox);
            container.AddSingleton <UseInboxHandler <MyEvent> >();


            var handlerFactory = new ServiceProviderHandlerFactory(container.BuildServiceProvider());

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .Retry();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(1));

            var inboxConfiguration = new InboxConfiguration(
                InboxScope.All,                      //grab all the events
                onceOnly: true,                      //only allow once
                actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should  be the only entry after)
                );

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                (IAmAHandlerFactory)handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            },
                inboxConfiguration: inboxConfiguration
                );
            PipelineBuilder <MyEvent> .ClearPipelineCache();
        }
コード例 #3
0
        private void RegisterBrighterHandlersFromAssembly(Type interfaceType, IEnumerable <Assembly> assemblies, Assembly assembly, SubscriberRegistry subscriberRegistry)
        {
            assemblies = assemblies.Concat(new [] { assembly });
            var subscribers =
                from ti in assemblies.SelectMany(a => a.DefinedTypes).Distinct()
                where ti.IsClass && !ti.IsAbstract && !ti.IsInterface
                from i in ti.ImplementedInterfaces
                where i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == interfaceType
                select new
            {
                RequestType = i.GenericTypeArguments.First(),
                HandlerType = ti.AsType()
            };

            foreach (var subscriber in subscribers)
            {
                _container.Register(subscriber.HandlerType, subscriber.HandlerType, Lifestyle.Scoped);
                subscriberRegistry.Add(subscriber.RequestType, subscriber.HandlerType);
            }
        }
コード例 #4
0
        public CommandProcessorBuildDefaultInboxSendTests()
        {
            var subscriberRegistry = new SubscriberRegistry();

            //This handler has no Inbox attribute
            subscriberRegistry.Add(typeof(MyCommand), typeof(MyCommandHandler));

            var container      = new TinyIoCContainer();
            var handlerFactory = new TinyIocHandlerFactory(container);

            container.Register <IHandleRequests <MyCommand>, MyCommandHandler>();
            container.Register <IAmAnInbox>(_inbox);

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .Retry();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(1));

            var inboxConfiguration = new InboxConfiguration(
                InboxScope.All,                      //grab all the events
                onceOnly: true,                      //only allow once
                actionOnExists: OnceOnlyAction.Throw //throw on duplicates (we should  be the only entry after)
                );

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            },
                inboxConfiguration: inboxConfiguration
                );

            PipelineBuilder <MyCommand> .ClearPipelineCache();
        }
コード例 #5
0
        public static SubscriberRegistry RegisterCommandHandlers(this SubscriberRegistry registry,
                                                                 IEnumerable <Type> commandHandlers, Action <DiscoveredPair> onDiscovery = null)
        {
            onDiscovery = onDiscovery ?? (_ => { });

            foreach (var handlerType in commandHandlers)
            {
                Type commandType     = null;
                var  handlerTypeInfo = handlerType.GetTypeInfo();

                if (handlerTypeInfo.IsGenericType)
                {
                    commandType = handlerTypeInfo.GetGenericArguments().First();
                }

                if (handlerTypeInfo.BaseType != null)
                {
                    var baseTypeInfo = handlerTypeInfo.BaseType.GetTypeInfo();
                    if (baseTypeInfo.IsGenericType)
                    {
                        commandType = baseTypeInfo.GetGenericArguments().First();
                    }
                }

                if (commandType == null)
                {
                    continue;
                }

                registry.Add(commandType, handlerType);
                onDiscovery(new DiscoveredPair {
                    Command = commandType, CommandHandler = handlerType
                });
            }

            return(registry);
        }
コード例 #6
0
 public void Add(Type requestType, Type handlerType)
 {
     _services.AddTransient(handlerType);
     _registry.Add(requestType, handlerType);
 }
 public void Add(Type requestType, Type handlerType)
 {
     _services.Add(new ServiceDescriptor(handlerType, handlerType, ServiceLifetime.Transient));
     _registry.Add(requestType, handlerType);
 }
コード例 #8
0
 public void Register(Type request, Type handler)
 {
     TinyIoCContainer.Current.Register(handler);
     _registry.Add(request, handler);
 }
コード例 #9
0
ファイル: HandlerFactory.cs プロジェクト: vendre21/Brighter
 public void Register(Type requestType, Type messageHandler)
 {
     _container.Register(messageHandler, messageHandler);
     _registry.Add(requestType, messageHandler);
 }
コード例 #10
0
 public void Register(Type request, Type handler)
 {
     _container.Register(handler);
     _registry.Add(request, handler);
 }
コード例 #11
0
 public void Register(Type request, Type handler)
 {
     _services.AddTransient(handler);
     _registry.Add(request, handler);
 }