Esempio n. 1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public IUser GetUserByAppConfiguration()
 {
     Unity.IUnityContainer unityContainer = new Unity.UnityContainer();
     unityContainer.LoadConfiguration("unityContainer");
     Strategy.IUser user = unityContainer.Resolve <Strategy.IUser>();
     user = user.GetUserById();
     return(user);
 }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IUser GetUserByUnityConfiguration()
        {
            Unity.IUnityContainer unityContainer = new UnityContainer();
            ////根据文件名获取指定config文件
            string filePath = AppDomain.CurrentDomain.BaseDirectory + @"Config\Unity.config";
            var    fileMap  = new ExeConfigurationFileMap {
                ExeConfigFilename = filePath
            };

            //从config文件中读取配置信息
            Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
            var           unitySection  = (UnityConfigurationSection)configuration.GetSection("unity");

            foreach (var item in unitySection.Containers)
            {
                unityContainer.LoadConfiguration(unitySection, item.Name);
            }
            Strategy.IUser user = unityContainer.Resolve <Strategy.IUser>();
            user = user.GetUserById();
            return(user);
        }