标签:
using Spring.Context; using Spring.Context.Support; namespace YTO.WeiXin.Core { public class SpringContainer { private static IApplicationContext AppCxt; /// <summary> /// 获取上下文 /// </summary> /// <returns>上下文对象</returns> public static IApplicationContext GetContext() { AppCxt = ContextRegistry.GetContext(); return AppCxt; } /// <summary> /// 上下文是否包含指定Id的对象 /// </summary> /// <param name="id">对象Id</param> /// <returns>true or false</returns> public static bool ContainObject(string id) { return GetContext().ContainsObject(id); } /// <summary> /// 获取对象 /// </summary> /// <typeparam name="T">对象类型</typeparam> /// <param name="id">对象的Id</param> /// <returns>T类型的对象</returns> public static T GetObject<T>(string id) where T : class { return GetContext().GetObject(id) as T; } } }
标签:
原文地址:http://www.cnblogs.com/slu182/p/4252754.html