Exemple #1
0
        /// <summary>
        /// 每次都注入新的对象
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <typeparam name="T2"></typeparam>
        /// <returns></returns>

        /// <summary>
        /// 每次都注入新的对象
        /// </summary>
        /// <typeparam name="T1"></typeparam>
        /// <param name="t2"></param>
        /// <returns></returns>
        public IServiceCollection AddTransient <T>(T t2)
        {
            Type             t       = typeof(T);
            ServiceTypeCache service = new ServiceTypeCache(t2, ServiceLifetime.Transient);

            if (!_typePairs.TryAdd(t, service))
            {
                throw new Exception("在注入对象时,有相同对象存在");
            }
            return(this);
        }
Exemple #2
0
        public IServiceCollection AddTransient <T1, T2>() where T2 : T1
        {
            Type             t1      = typeof(T1);
            Type             t2      = typeof(T2);
            ServiceTypeCache service = new ServiceTypeCache(t2, ServiceLifetime.Transient);

            if (!_typePairs.TryAdd(t1, service))
            {
                throw new Exception("在注入对象时,有相同对象存在");
            }
            return(this);
        }