private static void RegisterHandler(object handler, Type eventDataType, InProcessEventBus target)
        {
            var registerHandlerMethod = target.GetType().GetMethods().Single
                                        (
                m => m.Name == "RegisterHandler" && m.IsGenericMethod && m.GetParameters().Count() == 1
                                        );

            var targetMethod = registerHandlerMethod.MakeGenericMethod(new[] { eventDataType });

            targetMethod.Invoke(target, new object[] { handler });

            _log.InfoFormat("Registered {0} as event handler for event {1}.", handler.GetType().FullName, eventDataType.FullName);
        }
        public static void RegisterAllHandlersInAssembly(this InProcessEventBus target, Assembly asm, Func <Type, object> handlerFactory)
        {
            foreach (var type in asm.GetTypes().Where(ImplementsAtLeastOneIEventHandlerInterface))
            {
                var handler = handlerFactory(type);

                foreach (var handlerInterfaceType in type.GetInterfaces().Where(IsIEventHandlerInterface))
                {
                    var eventDataType = handlerInterfaceType.GetGenericArguments().First();
                    RegisterHandler(handler, eventDataType, target);
                }
            }
        }
 public static void RegisterAllHandlersInAssembly(this InProcessEventBus target, Assembly asm)
 {
     target.RegisterAllHandlersInAssembly(asm, CreateInstance);
 }
Пример #4
0
 private static IEventBus InializeEventBus()
 {
     var bus = new Ncqrs.Eventing.ServiceModel.Bus.InProcessEventBus();
     bus.RegisterHandler<NewClassifiedCreated>(new ClassifiedDenormalizer());
     return bus;
 }