예제 #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>();
        }
예제 #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>();
        }
예제 #3
0
 /// <summary>
 /// 获取接口
 /// </summary>
 /// <param name="fullName">接口的FullName</param>
 /// <param name="obj">返回的对象</param>
 /// <param name="execType">对象类型</param>
 /// <param name="session">连接对象</param>
 /// <param name="info">请求信息</param>
 /// <param name="requestInfo">基础请求信息</param>
 /// <param name="container">容器对象</param>
 /// <param name="requestClientSession">转发对象</param>
 /// <returns></returns>
 public bool GetService(string fullName, Session session, Info info, RequestInfo requestInfo, IUnityContainer container, Guid?requestClientSession, out Object obj, out Type execType)
 {
     if (ContainerObjList.TryGetValue(fullName, out var value))
     {
         obj      = unityContainer.Resolve(value.Item1);
         execType = value.Item2;
         if (value.Item3)
         {
             //表示可以注入某些属性
             socketPropertyInfo.SetValue(obj, session);
             infoPropertyInfo.SetValue(obj, info);
             requestInfoPropertyInfo.SetValue(obj, requestInfo);
             containerPropertyInfo.SetValue(obj, container);
             RequestClientSession?.SetValue(obj, requestClientSession);
         }
         return(true);
     }
     obj      = null;
     execType = null;
     return(false);
 }