コード例 #1
0
 private void AddEntry(DependencyEntry entry)
 {
     lock (_sync)
     {
         Last.Next = entry;
         Last      = entry.Last;
         Last.Last = entry.Last;
     }
 }
コード例 #2
0
        private DependencyEntry(Type serviceType, DependencyLifetime lifetime)
        {
            if (serviceType == null)
            {
                throw new ArgumentNullException(nameof(serviceType));
            }

            if (serviceType.IsGenericTypeDefinition)
            {
                throw new ArgumentOutOfRangeException(nameof(serviceType), "服务类型不能为泛型类型定义。");
            }

            ServiceType = serviceType;
            Lifetime    = lifetime;
            Last        = this;
        }
コード例 #3
0
        /// <summary>
        /// 添加依赖注入的实现
        /// </summary>
        /// <param name="dependencyEntry"></param>
        public void Add(DependencyEntry dependencyEntry)
        {
            if (dependencyEntry == null)
            {
                throw new ArgumentNullException(nameof(dependencyEntry));
            }

            if (ServiceType != dependencyEntry.ServiceType)
            {
                throw new ArgumentOutOfRangeException(nameof(dependencyEntry), "当前注册的服务类型需于目标服务类型一致。");
            }

            if (GetImplementationType() == dependencyEntry.GetImplementationType())
            {
                throw new ArgumentOutOfRangeException(nameof(dependencyEntry), "已注册" + dependencyEntry.ServiceType.FullName + "相同的实现类型。");
            }

            AddEntry(dependencyEntry);
        }
コード例 #4
0
 /// <summary>
 /// 将依赖注入对象添加到容器中
 /// </summary>
 /// <param name="dependencyEntry"></param>
 public void Add(DependencyEntry dependencyEntry)
 {
     if (dependencyEntry == null)
     {
         throw new ArgumentNullException(nameof(dependencyEntry));
     }
     lock (_sync)
     {
         var serviceType = dependencyEntry.ServiceType;
         if (_dependencyDictionary.ContainsKey(serviceType))
         {
             _dependencyDictionary[serviceType].Add(dependencyEntry);
         }
         else
         {
             _dependencyDictionary.Add(serviceType, dependencyEntry);
         }
     }
 }