public override bool Equals(object obj) { if (obj is ObjectIOCTypeInfo) { ObjectIOCTypeInfo inputInfo = obj as ObjectIOCTypeInfo; return(inputInfo.UseType == this.UseType && inputInfo.UseName == this.UseName); } else { return(base.Equals(obj)); } }
/// <summary> /// 注册一个外部对象 /// </summary> /// <param name="inputInfo"></param> public void RegistOneObjectInfo(ObjectIOCTypeInfo inputInfo) { if (null == inputInfo) { return; } if (!string.IsNullOrWhiteSpace(inputInfo.UseName)) { m_useContainer.RegisterInstance(inputInfo.UseType, inputInfo.UseObject); } else { m_useContainer.RegisterInstance(inputInfo.UseType, inputInfo.UseName, inputInfo.UseObject); } }
/// <summary> /// 基于类型扫描形式的注册 /// </summary> /// <param name="oneType"></param> private void RegisitOneTypeByBeanScan(Type oneType) { foreach (var oneMethod in oneType.GetMethods(BindingFlags.Public | BindingFlags.Static)) { BeanAttribute tempAttribute = oneMethod.GetCustomAttribute(m_useBeanType) as BeanAttribute; //若没有特性或存在参数或没有返回值 if (null == tempAttribute || oneMethod.GetParameters().Count() > 0 || oneMethod.ReturnType == m_useVoidType) { continue; } object tempObject; //创建对象 try { tempObject = oneMethod.Invoke(null, new Object[] { }); } catch (Exception) { continue; } ObjectIOCTypeInfo tempTypeInfo; if (!tempAttribute.RegistByClass) { //已接口形式注入 foreach (var oneInterfaceType in tempObject.GetType().GetInterfaces()) { tempTypeInfo = new ObjectIOCTypeInfo(oneInterfaceType, tempObject, tempAttribute.Name); m_useTypeService.RegistOneObjectInfo(tempTypeInfo); } } else { tempTypeInfo = new ObjectIOCTypeInfo(tempObject.GetType(), tempObject, tempAttribute.Name); m_useTypeService.RegistOneObjectInfo(tempTypeInfo); } } }