using System;
namespace NewLife.Model
{
/// <summary>·þÎñÈÝÆ÷»ùÀࡣʹÓ÷ºÐÍ»ùÀ࣬½ö½öÊÇΪÁËÒý·¢×ÓÀàµÄ¾²Ì¬¹¹Ô캯Êý¡£</summary>
/// <typeparam name="TService">¾ßÌå·þÎñÈÝÆ÷Àà</typeparam>
/// <remarks>
/// ½¨Òé¸÷¸ö×é¼þͨ¹ý¼Ì³Ðµ±Ç°ÀàʵÏÖÒ»¸ö˽ÓеķþÎñ¶¨Î»Æ÷£¬ÓÃÓÚΪ×é¼þÄÚÌṩ·þÎñ¶¨Î»·þÎñ¡£
/// ×é¼þÄÚ²¿µÄĬÈÏʵÏÖ¿ÉÒÔÔÚ¾²Ì¬¹¹Ô캯ÊýÖнøÐÐÎÞ¸²¸Ç×¢²á¡£
/// ×÷ΪԼ¶¨£¬×é¼þÄÚ²¿µÄ·þÎñ¶¨Î»È«²¿Í¨¹ý¸ÃÀàÍê³É£¬±£Ö¤·þÎñÔÚʹÓÃÇ°ÒÑÍê³ÉÁË×¢²á¡£
/// </remarks>
public class ServiceContainer<TService> where TService : ServiceContainer<TService>, new()
{
#region ¾²Ì¬¹¹Ô캯Êý
static ServiceContainer()
{
// ʵÀý»¯Ò»¸ö¶ÔÏó£¬ÎªÁË´¥·¢×ÓÀàµÄ¾²Ì¬¹¹Ô캯Êý
TService service = new TService();
}
#endregion
#region µ±Ç°¾²Ì¬·þÎñÈÝÆ÷
/// <summary>µ±Ç°¶ÔÏóÈÝÆ÷</summary>
public static IObjectContainer Container { get { return ObjectContainer.Current; } }
#endregion
#region ·þÎñ
/// <summary>×¢²áÀàÐͺÍÃû³Æ</summary>
/// <typeparam name="TInterface">½Ó¿ÚÀàÐÍ</typeparam>
/// <typeparam name="TImplement">ʵÏÖÀàÐÍ</typeparam>
/// <param name="id">±êʶ</param>
/// <param name="priority">ÓÅÏȼ¶</param>
/// <returns></returns>
public static IObjectContainer Register<TInterface, TImplement>(Object id = null, Int32 priority = 0) { return Container.Register<TInterface, TImplement>(id, priority); }
/// <summary>×¢²á</summary>
/// <typeparam name="T"></typeparam>
/// <param name="impl"></param>
/// <param name="id">±êʶ</param>
/// <returns></returns>
public static IObjectContainer Register<T>(Type impl, Object id = null) { return Container.Register(typeof(T), impl, id); }
/// <summary>½âÎöÀàÐÍÖ¸¶¨Ãû³ÆµÄʵÀý</summary>
/// <param name="type"></param>
/// <param name="id">±êʶ</param>
/// <param name="extend"></param>
/// <returns></returns>
public static Object Resolve(Type type, Object id = null, Boolean extend = false) { return Container.Resolve(type, id, extend); }
/// <summary>½âÎöÀàÐÍÖ¸¶¨Ãû³ÆµÄʵÀý</summary>
/// <typeparam name="TInterface">½Ó¿ÚÀàÐÍ</typeparam>
/// <param name="id">±êʶ</param>
/// <param name="extend">À©Õ¹¡£ÈôΪture£¬nameΪnull¶øÕÒ²»µ½Ê±£¬²ÉÓõÚÒ»¸ö×¢²áÏname²»Îªnull¶øÕÒ²»µ½Ê±£¬²ÉÓÃnull×¢²áÏî</param>
/// <returns></returns>
public static TInterface Resolve<TInterface>(Object id = null, Boolean extend = false) { return Container.Resolve<TInterface>(id, extend); }
/// <summary>½âÎöÀàÐÍÖ¸¶¨Ãû³ÆµÄʵÀý</summary>
/// <param name="type"></param>
/// <param name="id">±êʶ</param>
/// <param name="extend"></param>
/// <returns></returns>
public static Object ResolveInstance(Type type, Object id = null, Boolean extend = false) { return Container.ResolveInstance(type, id, extend); }
/// <summary>½âÎöÀàÐÍÖ¸¶¨Ãû³ÆµÄʵÀý</summary>
/// <typeparam name="TInterface">½Ó¿ÚÀàÐÍ</typeparam>
/// <param name="id">±êʶ</param>
/// <param name="extend">À©Õ¹¡£ÈôΪture£¬nameΪnull¶øÕÒ²»µ½Ê±£¬²ÉÓõÚÒ»¸ö×¢²áÏname²»Îªnull¶øÕÒ²»µ½Ê±£¬²ÉÓÃnull×¢²áÏî</param>
/// <returns></returns>
public static TInterface ResolveInstance<TInterface>(Object id = null, Boolean extend = false) { return Container.ResolveInstance<TInterface>(id, extend); }
/// <summary>½âÎöÀàÐÍ</summary>
/// <typeparam name="TInterface">½Ó¿ÚÀàÐÍ</typeparam>
/// <param name="id">±êʶ</param>
/// <param name="extend">À©Õ¹¡£ÈôΪture£¬nameΪnull¶øÕÒ²»µ½Ê±£¬²ÉÓõÚÒ»¸ö×¢²áÏname²»Îªnull¶øÕÒ²»µ½Ê±£¬²ÉÓÃnull×¢²áÏî</param>
/// <returns></returns>
public static Type ResolveType<TInterface>(Object id = null, Boolean extend = false) { return Container.ResolveType(typeof(TInterface), id, extend); }
#endregion
}
}
|