Ejemplo n.º 1
0
        /// <summary>
        ///     初始化该类型
        /// </summary>
        protected void Initialize(IObjectContainer container, Type messageType)
        {
            var contractType = typeof(IEnvelopedMessageHandler <>).MakeGenericType(messageType);
            var handlers     = container.ResolveAll(contractType).ToArray();

            if (handlers.Length > 0)
            {
                _envelopeHandlerDescriptors[messageType] = handlers.Select(handler =>
                                                                           new HandlerDescriptor(handler, handlerType => handlerType.GetMethod("Handle", new[] { typeof(Envelope <>).MakeGenericType(messageType) }), HandlerStyle.Senior)).ToArray();

                if (_checkHandlerMode == CheckHandlerMode.OnlyOne)
                {
                    if (handlers.Length > 1)
                    {
                        throw new SystemException(
                                  string.Format(
                                      "Found more than one handler for this type('{0}') with IEnvelopedMessageHandler<>.",
                                      messageType.FullName));
                    }

                    return;
                }
            }

            contractType = typeof(IMessageHandler <>).MakeGenericType(messageType);
            handlers     = container.ResolveAll(contractType).ToArray();
            if (_checkHandlerMode == CheckHandlerMode.OnlyOne)
            {
                switch (handlers.Length)
                {
                case 0:
                    throw new SystemException(
                              string.Format("The handler of this type('{0}') is not found.", messageType.FullName));

                case 1:
                    break;

                default:
                    throw new SystemException(
                              string.Format(
                                  "Found more than one handler for '{0}' with IMessageHandler<>.",
                                  messageType.FullName));
                }
            }

            if (handlers.Length > 0)
            {
                _handlerDescriptors[messageType] = handlers.Select(handler =>
                                                                   new HandlerDescriptor(handler, handlerType => handlerType.GetMethod("Handle", new[] { messageType }), HandlerStyle.Simple)).ToArray();
            }
        }
        public void GivenImUsing(WebDriverInstanceType browser)
        {
            if (_objectContainer.ResolveAll <IQAWebDriver>().Any())
            {
                throw new DuplicateWebDriverInstanceTypeException("Web Driver Instance Type is already defined");
            }

            //Can use Enum.Parse instead of Step Argument Transformation.
            switch (browser)
            {
            case WebDriverInstanceType.Chrome:
                _objectContainer.RegisterInstanceAs <IQAWebDriver>(new ChromeQAWebDriver());
                break;

            case WebDriverInstanceType.FireFox:
                _objectContainer.RegisterInstanceAs <IQAWebDriver>(new FirefoxQAWebDriver());
                break;

            case WebDriverInstanceType.InternetExplorer:
                _objectContainer.RegisterInstanceAs <IQAWebDriver>(new IeQAWebDriver());
                break;

            case WebDriverInstanceType.PhantomJS:
                _objectContainer.RegisterInstanceAs <IQAWebDriver>(new PhantomJSQAWebDriver());
                break;

            default:
                throw new NotImplementedWebDriverInstanceTypeException(string.Format("{0} Web Driver Type is Not Implemented", browser));
            }
        }
Ejemplo n.º 3
0
 public IEnumerable <object> GetServices(Type serviceType)
 {
     foreach (object s in Container.ResolveAll(serviceType))
     {
         yield return(s);
     }
 }
Ejemplo n.º 4
0
        public void Initialize(IObjectContainer container, IEnumerable <Type> types)
        {
            var versionedEventType = typeof(IVersionedEvent);

            BasicTypes.EventTypes.Values.ForEach(eventType => {
                if (versionedEventType.IsAssignableFrom(eventType))
                {
                    var eventHandlers =
                        container.ResolveAll(typeof(IEventHandler <>).MakeGenericType(eventType))
                        .ToList();
                    switch (eventHandlers.Count)
                    {
                    case 0:
                        break;

                    case 1:
                        _eventHandlerDescriptors[eventType] = new HandlerDescriptor(eventHandlers[0], handlerType => handlerType.GetMethod("Handle", new[] { typeof(IEventContext), eventType }), HandlerStyle.Special);
                        break;

                    default:
                        throw new SystemException(string.Format(
                                                      "Found more than one handler for '{0}' with IEventHandler<>.",
                                                      eventType.FullName));
                    }
                }

                Initialize(container, eventType);
            });
        }
Ejemplo n.º 5
0
        public void Initialize(IObjectContainer container, IEnumerable <Type> types)
        {
            BasicTypes.CommandTypes.Values.ForEach(commandType => {
                var commandHandlers =
                    container.ResolveAll(typeof(ICommandHandler <>).MakeGenericType(commandType)).ToList();
                switch (commandHandlers.Count)
                {
                case 0:
                    break;

                case 1:
                    _commandHandlerDescriptors[commandType] = new HandlerDescriptor(commandHandlers[0], handlerType => handlerType.GetMethod("Handle", new[] { typeof(ICommandContext), commandType }), HandlerStyle.Special);
                    break;

                default:
                    throw new SystemException(string.Format(
                                                  "Found more than one handler for this type('{0}') with ICommandHandler<>.",
                                                  commandType.FullName));
                }
                if (commandHandlers.Count == 0)
                {
                    Initialize(container, commandType);
                }
                var handlerDescriptor = GetHandlerDescriptors(commandType).First();
                var callHandlers      = HandlerAttributeHelper.GetHandlersFor(handlerDescriptor.Method, container);
                _pipelineManager.InitializePipeline(handlerDescriptor.Method, callHandlers);
            });
        }
Ejemplo n.º 6
0
        public void Initialize(IObjectContainer container, IEnumerable <Type> types)
        {
            var contactTypeMap = new Dictionary <Type, Type>();

            types.Where(type => type.IsClass && !type.IsAbstract)
            .ForEach(type => {
                type.GetInterfaces().Where(interfaceType => interfaceType.IsGenericType &&
                                           interfaceType.GetGenericTypeDefinition() == typeof(IQueryHandler <,>))
                .ForEach(interfaceType => {
                    var queryType = interfaceType.GetGenericArguments().First();
                    if (contactTypeMap.ContainsKey(queryType))
                    {
                        var errorMessage = string.Format(
                            "There are have duplicate IQueryHandler<> interface type for {0}.",
                            queryType.FullName);
                        throw new SystemException(errorMessage);
                    }

                    contactTypeMap[queryType] = interfaceType;
                });
            });

            BasicTypes.QueryTypes.Values.ForEach(queryType => {
                Type contactType;
                if (!contactTypeMap.TryGetValue(queryType, out contactType))
                {
                    var errorMessage = string.Format("The query handler of this type('{0}') is not found.",
                                                     queryType.FullName);
                    throw new SystemException(errorMessage);
                }

                var handlers = container.ResolveAll(contactType).ToList();
                switch (handlers.Count)
                {
                case 0:
                    var errorMessage = string.Format("The query handler for {0} is not found.",
                                                     contactType.GetFriendlyTypeName());
                    throw new SystemException(errorMessage);

                case 1:
                    var handlerDescriptor          = new HandlerDescriptor(handlers[0], handlerType => handlerType.GetMethod("Handle", new[] { queryType }), HandlerStyle.Special);
                    _handlerDescriptors[queryType] = handlerDescriptor;
                    var callHandlers = HandlerAttributeHelper.GetHandlersFor(handlerDescriptor.Method, container);
                    _pipelineManager.InitializePipeline(handlerDescriptor.Method, callHandlers);
                    break;

                default:
                    errorMessage = string.Format(
                        "Found more than one handler for '{0}' with IQueryHandler<>.",
                        queryType.FullName);
                    throw new SystemException(errorMessage);
                }
            });
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 解析所有指定类型的服务对象
 /// </summary>
 /// <param name="serviceType">要解析的服务对象</param>
 /// <returns><see cref="System.Array"/>所有解析的服务对象实例</returns>
 public Array ResolveAll(Type serviceType)
 {
     return(objectContainer.ResolveAll(serviceType));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// 获取类型所有的实例
 /// </summary>
 /// <typeparam name="T">注册类型</typeparam>
 /// <param name="that">容器</param>
 public static IEnumerable <T> ResolveAll <T>(this IObjectContainer that)
 {
     return(that.ResolveAll(typeof(T)).Cast <T>().ToArray());
 }
 /// <summary>
 /// 如果某个服务有多个实例,则可以使用此方法来获取所有的实例。
 /// </summary>
 /// <param name="serviceType"></param>
 /// <returns></returns>
 public IEnumerable <object> GetAllInstances(Type serviceType)
 {
     return(_container.ResolveAll(serviceType));
 }
Ejemplo n.º 10
0
 public T[] ResolveAll <T>()
 {
     return(objectContainer.ResolveAll <T>());
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 获取指定类型的所有实例。
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="container"></param>
 /// <returns></returns>
 public static IEnumerable <T> ResolveAll <T>(this IObjectContainer container)
     where T : class
 {
     return(container.ResolveAll(typeof(T)).Cast <T>());
 }
Ejemplo n.º 12
0
 public FeatureGeneratorRegistry(IObjectContainer objectContainer)
 {
     providers = objectContainer.ResolveAll <IFeatureGeneratorProvider>().ToList().OrderBy(item => item.Priority).ToList();
 }
Ejemplo n.º 13
0
 public T[] ResolveAll <T>() where T : class
 {
     return(_container.ResolveAll <T>());
 }
Ejemplo n.º 14
0
        public void CleanWebDriver()
        {
            var webDriver = _objectContainer.ResolveAll <IWebDriver>().FirstOrDefault();

            webDriver?.Close();
        }
Ejemplo n.º 15
0
 protected override IEnumerable <object> DoGetAllInstances(Type serviceType)
 {
     return(_container.ResolveAll(serviceType));
 }
Ejemplo n.º 16
0
 protected override void Start()
 {
     _container.ResolveAll <IProcessor>().ForEach(p => p.Start());
 }