Exemplo n.º 1
0
        public IEventBus CreateEventBus(IContainer container)
        {
            // should not happen, but does sometimes.
            // seems related to Mvc contra WebApi
            // but can't figure out why
            if (_eventBus != null)
            {
                return(_eventBus);
            }

            _registry.ScanAssembly(typeof(ValidateNewLoginHandler).Assembly);
            _registry.ScanAssembly(typeof(UserRepository).Assembly);
            _registry.ScanAssembly(typeof(ScanForNewErrorReports).Assembly);

            //var inner = new SeparateScopesIocEventBus(container, _registry);
            var inner = new IocEventBus(container);

            inner.EventPublished += (sender, args) => CloseUnitOfWorks(args.Scope);
            //inner.ScopeClosing += (sender, args) => CloseUnitOfWorks(args.Scope);
            inner.HandlerFailed += (sender, args) =>
            {
                foreach (var failure in args.Failures)
                {
                    _log.Error(failure.Handler.GetType().FullName + " failed to handle " + args.ApplicationEvent,
                               failure.Exception);
                }
            };

            var bus = new QueuedEventBus(inner, _queueProvider);

            _eventBus = bus;

            return(bus);
        }
Exemplo n.º 2
0
        public IEventBus CreateEventBus(IContainer container)
        {
            var registry = new EventHandlerRegistry();

            registry.ScanAssembly(typeof(ValidateNewLoginHandler).Assembly);
            registry.ScanAssembly(typeof(UserRepository).Assembly);
            registry.ScanAssembly(typeof(ScanForNewErrorReports).Assembly);

            var inner = new SeparateScopesIocEventBus(container, registry);
            var bus   = new QueuedEventBus(inner, _queueProvider);

            inner.ScopeClosing  += (sender, args) => CloseUnitOfWorks(args.Scope);
            inner.HandlerFailed += (sender, args) =>
            {
                foreach (var failure in args.Failures)
                {
                    _log.Error(failure.Handler.GetType().FullName + " failed to handle " + args.ApplicationEvent,
                               failure.Exception);
                }
            };
            bus.Start();

            return(bus);
        }