Exemplo n.º 1
0
        private static IIocContainer SetContainer(IIocContainer value)
        {
            var config = value.Get("$AppSettings") as NameValueCollection
                         ?? AppSettings
                         ?? new NameValueCollection();

            var redisAddress = config.Get("redis.address");

            if (!string.IsNullOrWhiteSpace(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.Add <IRedisProvider>(new RedisProvider(value));
            }

            if (!value.Contains <IUserFactory>(true))
            {
                value.Add <IUserFactory>(value.Get <IIdentityStore>());
            }

            _WebContainer = value;
            return(value);
        }
Exemplo n.º 2
0
    /// <summary>
    /// 查找服务容器是否包含指定关联的服务类型指定的参数。
    /// </summary>
    /// <typeparam name="TService">要添加的服务类型。</typeparam>
    /// <param name="container">服务容器。</param>
    /// <param name="name">要查找的参数名称。</param>
    /// <param name="promote">true,则将此请求提升到任何父服务容器;否则为 false。</param>
    /// <returns>如果存在返回 true,否则返回 false。</returns>
    public static bool Contains <TService>(this IIocContainer container, string name, bool promote = false)
    {
        if (container == null)
        {
            throw new ArgumentNullException(nameof(container));
        }

        return(container.Contains(typeof(TService), name, promote));
    }