/// <summary> /// 전달된 <paramref name="type"/>유형에 선언된 Autowire 특성을 분석하여 Spring Context에 등록하고, 객체를 생성하여 반환합니다. /// </summary> /// <param name="type"></param> /// <param name="rootContextName"></param> /// <returns></returns> public static object Autowire(Type type, string rootContextName = DefaultRootContextName) { AutowireAttribute autowireAttribute = type.GetCustomAttribute <AutowireAttribute>(); if (autowireAttribute == null) { autowireAttribute = new AutowireAttribute { ContextName = $"[{type.GetShortAssemblyName()}]{"Singleton=true".ToMD5String()}", Type = type, Singleton = false }; } return(Autowire(type, autowireAttribute, rootContextName)); }
/// <summary> /// <paramref name="type"/> 유형과 <paramref name="autowireAttribute"/>의 Autowire 특성을 분석하여 Spring Context에 등록하고, 객체를 생성하여 반환합니다. /// </summary> /// <param name="type"></param> /// <param name="autowireAttribute"></param> /// <param name="rootContextName"></param> /// <returns></returns> public static object Autowire(Type type, AutowireAttribute autowireAttribute, string rootContextName = DefaultRootContextName) { AbstractApplicationContext ctx = GetApplicationContext(rootContextName); if (autowireAttribute == null) { throw new NullReferenceException("AutowireAttribute missing"); } if (autowireAttribute.Type == null) { autowireAttribute.Type = type; } if (string.IsNullOrEmpty(autowireAttribute.ContextName)) { autowireAttribute.ContextName = $"[{type.GetShortAssemblyName()}]{$"Singleton={autowireAttribute.Singleton.ToString().ToLower()}".ToMD5String()}"; } var info = new AutowireTargetPropertyInfo(autowireAttribute, type); CreateObjectDefinition(ctx, info); return(ctx.GetObject(info.ObjectInfo.Id)); }
/// <summary> /// 유형 <typeparamref name="T"/>을 전달된 <paramref name="autowireAttribute"/> Autowire 특성을 분석하여 Spring Context에 등록하고, 객체를 생성하여 반환합니다. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="autowireAttribute"></param> /// <param name="rootContextName"></param> /// <returns></returns> public static T Autowire <T>(AutowireAttribute autowireAttribute, string rootContextName = DefaultRootContextName) { return((T)Autowire(typeof(T), autowireAttribute, rootContextName)); }
/// <summary> /// AutowireTargetPropertyInfo /// 유형으로 부터 정보를 가져올 때 사용합니다. /// </summary> /// <param name="autowireAttribute"></param> /// <param name="type"></param> public AutowireTargetPropertyInfo(AutowireAttribute autowireAttribute, Type type) { ObjectInfo = new ObjectInfo(autowireAttribute, type); }