예제 #1
0
        private void Kernel_ComponentRegistered(string key, IHandler handler)
        {
            if (!typeof(Base.IHandler).GetTypeInfo().IsAssignableFrom(handler.ComponentModel.Implementation))
            {
                return;
            }

            var interfaces = handler.ComponentModel.Implementation.GetTypeInfo().GetInterfaces();

            foreach (var aInterface in interfaces)
            {
                if (!typeof(Base.IHandler).GetTypeInfo().IsAssignableFrom(aInterface))
                {
                    continue;
                }

                var genericArgs = aInterface.GetGenericArguments();
                if (genericArgs.Length == 1)
                {
                    if (typeof(IRequestHandler).GetTypeInfo().IsAssignableFrom(aInterface))
                    {
                        _serviceBus.AddRequestHandler(genericArgs[0], new Base.IocHandlerFactory(handler.ComponentModel.Implementation, genericArgs[0]));
                    }
                    else
                    {
                        _serviceBus.AddSubscription(genericArgs[0], new Base.IocHandlerFactory(handler.ComponentModel.Implementation, genericArgs[0]));
                    }
                }
            }
        }