/// <summary> /// 注册类型与名称 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="oneType"></param> /// <param name="tempAttribute"></param> /// <param name="tempBuilder"></param> /// <returns></returns> private IRegistrationBuilder <object, T, SingleRegistrationStyle> PrepareCalssAndName <T> (Type oneType, INameAndCalssAttribute tempAttribute, IRegistrationBuilder <object, T, SingleRegistrationStyle> tempBuilder) where T : IConcreteActivatorData { //类型注册/接口注册 if (tempAttribute.IfByClass) { tempBuilder = tempBuilder.As(oneType); } else { tempBuilder = tempBuilder.AsImplementedInterfaces(); } //设置注册名称 if (!string.IsNullOrWhiteSpace(tempAttribute.Name)) { //按类型注册 if (tempAttribute.IfByClass) { tempBuilder = tempBuilder.Keyed(tempAttribute.Name, oneType); } //按接口注册 else { foreach (var oneInterfaceType in oneType.GetInterfaces()) { tempBuilder = tempBuilder.Keyed(tempAttribute.Name, oneInterfaceType); } } } return(tempBuilder); }
/// <summary> /// 注册Bean /// </summary> /// <param name="inputObj"></param> /// <param name="tempAttribute"></param> private void RegiestBean(object inputObj, INameAndCalssAttribute tempAttribute) { var tempBuilder = m_containerBuilder.RegisterInstance(inputObj); //按name与class注册 tempBuilder = PrepareCalssAndName(inputObj.GetType(), tempAttribute, tempBuilder); }
/// <summary> /// 泛型注册类型与名称 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="oneType"></param> /// <param name="tempAttribute"></param> /// <param name="tempBuilder"></param> /// <returns></returns> private IRegistrationBuilder <object, ReflectionActivatorData, DynamicRegistrationStyle> PrepareCalssAndName (Type oneType, INameAndCalssAttribute tempAttribute, IRegistrationBuilder <object, ReflectionActivatorData, DynamicRegistrationStyle> tempBuilder) { //类型注册/接口注册 if (tempAttribute.IfByClass) { tempBuilder = tempBuilder.As(oneType); } else { foreach (var oneInterface in oneType.GetInterfaces()) { if (oneInterface.IsGenericType) { tempBuilder.As(oneInterface); } } } //设置注册名称 if (!string.IsNullOrWhiteSpace(tempAttribute.Name)) { //按类型注册 if (tempAttribute.IfByClass) { tempBuilder = tempBuilder.Keyed(tempAttribute.Name, oneType); } //按接口注册 else { foreach (var oneInterfaceType in oneType.GetInterfaces()) { tempBuilder = tempBuilder.Keyed(tempAttribute.Name, oneInterfaceType); } } } return(tempBuilder); }