private static IIocContainer SetContainer(IIocContainer value) { var config = value.GetValue("$AppSettings") as NameValueCollection ?? System.Web.Configuration.WebConfigurationManager.AppSettings ?? new NameValueCollection(); var redisAddress = config.Get("reids.address"); if (!string.IsNullOrEmpty(redisAddress)) { var sp = redisAddress.Split(':'); if (sp.Length != 2) { throw new ArgumentException("非法的 Redis 的连接地址 {0}。".Fmt(redisAddress)); } Aoite.Redis.RedisManager.DefaultAddress = new Aoite.Net.SocketInfo(sp[0], int.Parse(sp[1])); } Aoite.Redis.RedisManager.DefaultPassword = config.Get("redis.password"); if (config.Get <bool>("redis.enabled")) { value.AddService <IRedisProvider>(new RedisProvider(value)); } if (!value.ContainsService <IUserFactory>(true)) { value.AddService <IUserFactory>(value.GetService <IIdentityStore>()); } HttpContext.Current.Application[ContainerName] = value; return(value); }
/// <summary> /// 查找服务容器是否包含指定的服务类型。 /// </summary> /// <typeparam name="TService">要添加的服务类型。</typeparam> /// <param name="container">服务容器。</param> /// <param name="promote">true,则将此请求提升到任何父服务容器;否则为 false。</param> /// <returns>如果存在返回 true,否则返回 false。</returns> public static bool ContainsService <TService>(this IIocContainer container, bool promote = false) { if (container == null) { throw new ArgumentNullException("container"); } return(container.ContainsService(typeof(TService), promote)); }