Ejemplo n.º 1
0
 public void AddOrUpdateImplement(Type interfaceType, InterfaceImplementer implementer)
 {
     _data.AddOrUpdate(interfaceType, implementer, (t, i) =>
     {
         return(implementer);
     });
 }
Ejemplo n.º 2
0
        public static InterfaceMapper Create(XmlNode section)
        {
            if (section == null)
            {
                return(null);
            }
            InterfaceMapper mapper     = new InterfaceMapper();
            var             implements = section.SelectNodes("implement");

            foreach (XmlNode implement in implements)
            {
                string contractTypeName = section.GetAttributeValue("contractType");
                ArgumentAssert.IsNotNull(contractTypeName, "contractTypeName");
                Type contractType = Type.GetType(contractTypeName);
                if (contractType == null)
                {
                    throw new NoTypeDefinedException(contractTypeName);
                }

                var imp = InterfaceImplementer.Create(implement);
                if (imp != null)
                {
                    mapper.AddImplement(contractType, imp);
                }
            }
            return(mapper);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 新增一个类型映射
 /// </summary>
 /// <param name="interfaceType">契约</param>
 /// <param name="implementer">实现</param>
 public void AddImplement(Type interfaceType, InterfaceImplementer implementer)
 {
     if (!_data.TryAdd(interfaceType, implementer))
     {
         throw new InvalidOperationException("已经存在类型" + interfaceType.FullName + "的实现");
     }
 }
Ejemplo n.º 4
0
        internal InterfaceImplementer GetImplementer(Type interfaceType)
        {
            InterfaceImplementer implement = null;

            if (_data.TryGetValue(interfaceType, out implement))
            {
                return(implement);
            }
            return(null);
        }
Ejemplo n.º 5
0
        public Type GetInstanceType(Type interfaceType)
        {
            InterfaceImplementer implement = null;

            if (!_data.TryGetValue(interfaceType, out implement))
            {
                throw new InvalidOperationException("不存在接口" + interfaceType.FullName + "的实现,无法获取实例类型");
            }
            return(implement.ImplementType);
        }
        public Type GetInstanceType(Type interfaceType)
        {
            InterfaceImplementer implement = null;

            if (!_data.TryGetValue(interfaceType, out implement))
            {
                throw new InvalidOperationException(string.Format(Strings.NoInterfaceImpl, interfaceType.FullName));
            }
            return(implement.ImplementType);
        }
Ejemplo n.º 7
0
        public T GetInstance <T>() where T : class
        {
            Type interfaceType             = typeof(T);
            InterfaceImplementer implement = null;

            if (!_data.TryGetValue(interfaceType, out implement))
            {
                throw new InvalidOperationException("不存在接口" + interfaceType.FullName + "的实现,无法获取实例");
            }
            return(implement.GetInstance <T>());
        }
        public T GetInstance <T>() where T : class
        {
            Type interfaceType             = typeof(T);
            InterfaceImplementer implement = null;

            if (!_data.TryGetValue(interfaceType, out implement))
            {
                throw new InvalidOperationException(string.Format(Strings.NoInterfaceImpl, interfaceType.FullName));
            }
            return(implement.GetInstance <T>());
        }
Ejemplo n.º 9
0
        public void LoadFrom(XmlNode section)
        {
            var sessionNode = section.SelectSingleNode("session");

            this.AppSessionImplementer = InterfaceImplementer.Create(sessionNode);
        }