예제 #1
0
        /// <summary>
        /// 通过关联的服务类型查找配置
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public HttpServiceConfigureItem Get(Type type)
        {
            HttpServiceConfigureItem current = null;
            var enumer = GetEnumerator();

            while (enumer.MoveNext())
            {
                current = enumer.Current;
                if (current.ForTypes.FirstOrDefault(x => x == type) != null)
                {
                    return(current);
                }
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// 根据服务名称查找配置
        /// </summary>
        /// <param name="serviceName"></param>
        /// <returns></returns>
        public HttpServiceConfigureItem Get(string serviceName)
        {
            HttpServiceConfigureItem current = null;
            var enumer = GetEnumerator();

            while (enumer.MoveNext())
            {
                current = enumer.Current;
                if (current.ServiceName == serviceName)
                {
                    return(current);
                }
            }
            return(null);
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="interfaceSubType">表示当前类型为接口实现类</param>
        /// <returns></returns>
        public HttpServiceConfigureItem Get(Type type, bool interfaceSubType)
        {
            HttpServiceConfigureItem current = null;
            var enumer = GetEnumerator();

            while (enumer.MoveNext())
            {
                current = enumer.Current;
                var result = current.ForTypes.FirstOrDefault(x => x == type ||
                                                             (interfaceSubType && x.IsInterface && x.IsAssignableFrom(type)));
                if (result != null)
                {
                    return(current);
                }
            }
            return(null);
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public HttpServiceConfigureItem AddConfigure(HttpServiceConfigureItem config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (string.IsNullOrWhiteSpace(config.ServiceName))
            {
                throw new ArgumentNullException(nameof(config.ServiceName));
            }
            var configed = Get(config.ServiceName);

            if (configed != null)
            {
                throw new Exception($"请不要重复添加{config.ServiceName}服务");
            }
            _innerList.Add(config);
            return(config);
        }