Example #1
0
        /// <summary>
        /// 添加接口到容器中
        /// </summary>
        /// <typeparam name="IT">接口</typeparam>
        /// <typeparam name="T">实现</typeparam>
        public void AddProvideServices <IT, T>()
            where IT : class
            where T : IT, BaseProvideServicesT
        {
            var typeIT = typeof(IT);
            var typeT  = typeof(T);

            if (ContainerObjList.TryGetValue(typeIT.FullName, out var value))
            {
                throw new Exception($"对象中已经有{typeIT.FullName}存在");
            }
            ContainerObjList.Add(typeIT.FullName, new Tuple <Type, Type, bool>(typeIT, typeT, true));
            unityContainer.RegisterType <IT, T>();
        }
Example #2
0
        /// <summary>
        /// 添加接口到容器中
        /// </summary>
        /// <typeparam name="IT">接口</typeparam>
        /// <typeparam name="T">实现</typeparam>
        public void AddServer <IT, T>()
            where IT : class
            where T : IT
        {
            var typeIT = typeof(IT);
            var typeT  = typeof(T);

            if (ContainerObjList.TryGetValue(typeIT.FullName, out _))
            {
                throw new Exception($"对象中已经有{typeIT.FullName}存在");
            }
            ContainerObjList.Add(typeIT.FullName, new Tuple <Type, Type, bool>(typeIT, typeT, false));
            Container.RegisterType <IT, T>();
        }