public static TInterface ResolveInstance <TInterface>(this IObjectContainer container, Object id = null, Boolean extend = false) { var obj = container.ResolveInstance(typeof(TInterface), id, extend); try { return((TInterface)obj); } catch (InvalidCastException ex) { var t = obj.GetType(); NewLife.Log.XTrace.WriteLine("ObjectType:{0} {1}", t.AssemblyQualifiedName, t.Assembly.Location); t = typeof(TInterface); NewLife.Log.XTrace.WriteLine("InterfaceType:{0} {1}", t.AssemblyQualifiedName, t.Assembly.Location); throw ex; } }
/// <summary>解析类型指定名称的实例</summary> /// <typeparam name="TInterface">接口类型</typeparam> /// <param name="container">对象容器</param> /// <param name="id">标识</param> /// <returns></returns> public static TInterface ResolveInstance <TInterface>(this IObjectContainer container, Object id = null) { return((TInterface)container.ResolveInstance(typeof(TInterface), id)); }
/// <summary>解析类型指定名称的实例</summary> /// <typeparam name="TInterface">接口类型</typeparam> /// <param name="container">对象容器</param> /// <param name="id">标识</param> /// <param name="extend">扩展。若为ture,name为null而找不到时,采用第一个注册项;name不为null而找不到时,采用null注册项</param> /// <returns></returns> #if !DEBUG public static TInterface ResolveInstance <TInterface>(this IObjectContainer container, Object id = null, Boolean extend = false) { return((TInterface)container.ResolveInstance(typeof(TInterface), id, extend)); }