public void RegisterToManager(IEventHandlersManager eventHandlersManager, IEnumerable<Assembly> assemblies)
        {
            if (assemblies == null)
                throw new ArgumentNullException("assemblies");
            if (eventHandlersManager == null)
                throw new ArgumentNullException("eventHandlersManager");

            var publicTypes = assemblies.SelectMany(a => a.GetTypes())
                                        .Where(t => t.IsPublic && !t.IsAbstract && t.IsClass);

            foreach (var type in publicTypes)
            {
                if (type.IsInterface || type.IsAbstract)
                    continue;
                RegisterHandler(type, eventHandlersManager);
            }
        }
        private void RegisterHandler(Type type, IEventHandlersManager eventHandlersManager)
        {
            var interfaces = (from iface in type.GetInterfaces()
                              where iface.IsGenericType &&
                                    iface.GetGenericTypeDefinition() == typeof (IEventHandler<>)
                              select iface).ToArray();

            if (interfaces.Length == 0)
                return;

            var addHandlerGenericMethod = eventHandlersManager.GetType().GetMethod("Add");
            var handler = _container.Resolve(type);
            foreach (var @interface in interfaces)
            {
                var addHandlerMethod = addHandlerGenericMethod.MakeGenericMethod(@interface.GetGenericArguments());
                addHandlerMethod.Invoke(eventHandlersManager, new[] {handler});
            }
        }
예제 #3
0
        private void RegisterHandler(Type type, IEventHandlersManager eventHandlersManager)
        {
            var interfaces = (from iface in type.GetInterfaces()
                              where iface.IsGenericType &&
                              iface.GetGenericTypeDefinition() == typeof(IEventHandler <>)
                              select iface).ToArray();

            if (interfaces.Length == 0)
            {
                return;
            }

            var addHandlerGenericMethod = eventHandlersManager.GetType().GetMethod("Add");
            var handler = _container.Resolve(type);

            foreach (var @interface in interfaces)
            {
                var addHandlerMethod = addHandlerGenericMethod.MakeGenericMethod(@interface.GetGenericArguments());
                addHandlerMethod.Invoke(eventHandlersManager, new[] { handler });
            }
        }
예제 #4
0
        public void RegisterToManager(IEventHandlersManager eventHandlersManager, IEnumerable <Assembly> assemblies)
        {
            if (assemblies == null)
            {
                throw new ArgumentNullException("assemblies");
            }
            if (eventHandlersManager == null)
            {
                throw new ArgumentNullException("eventHandlersManager");
            }

            var publicTypes = assemblies.SelectMany(a => a.GetTypes())
                              .Where(t => t.IsPublic && !t.IsAbstract && t.IsClass);

            foreach (var type in publicTypes)
            {
                if (type.IsInterface || type.IsAbstract)
                {
                    continue;
                }
                RegisterHandler(type, eventHandlersManager);
            }
        }
예제 #5
0
 public SimpleEventPublisher(IEventHandlersManager eventHandlersManager)
 {
     _eventHandlersManager = eventHandlersManager;
 }