static DependencyResolver() { switch (ConfigurationManager.AppSettings["DAL"]) { case "Memory": _userDao = new UserOnMemoryDAO(); _awardDao = new AwardOnMemoryDAO(); _usersAndAwardsDao = new UsersAndAwardsOnMemoryDAO(); break; case "File": _userDao = new UserOnFileDAO(); _awardDao = new AwardOnFileDAO(); _usersAndAwardsDao = new UsersAndAwardsOnFileDAO(); _webUserDao = new WebUserFileDao(); _userRoleDao = new UserRoleFileDAO(); _imagesDao = new ImagesDAO(); _usersAndImagesDao = new UsersAndImagesOnFileDAO(); _awardsAndImagesDao = new AwardsAndImagesDAO(); break; case "Database": _userDao = new UserDatabaseDAO(); _awardDao = new AwardDatabaseDAO(); _usersAndAwardsDao = new UsersAndAwardsDatabaseDAO(); _webUserDao = new WebUserDatabaseDAO(); _userRoleDao = new UserRoleDatabaseDAO(); _imagesDao = new ImagesDatabaseDAO(); _usersAndImagesDao = new UsersAndImagesDatabaseDAO(); _awardsAndImagesDao = new AwardsAndImagesDatabaseDAO(); break; } _usersAndAwardsLogic = new UsersAndAwardsLogic(_usersAndAwardsDao); _webUserLogic = new WebUserLogic(_webUserDao); _userRoleLogic = new UserRoleLogic(_userRoleDao); _usersAndImagesLogic = new UsersAndImagesLogic(_usersAndImagesDao); _awardsAndImagesLogic = new AwardsAndImagesLogic(_awardsAndImagesDao); _userLogic = new UserLogic(_userDao, _usersAndAwardsDao, _usersAndImagesLogic); _awardLogic = new AwardLogic(_awardDao, _usersAndAwardsDao, _awardsAndImagesLogic); _imagesLogic = new ImagesLogic(_imagesDao, _usersAndImagesLogic, _awardsAndImagesLogic); }
static DependencyResolver() { CfgDto config = new CfgDto(); if (File.Exists(_path)) { var openCfgStream = File.Open(_path, FileMode.Open); XmlSerializer xCfg = new XmlSerializer(typeof(CfgDto)); config = (CfgDto)xCfg.Deserialize(openCfgStream); } else { var openCfgStream = File.Open(_path, FileMode.Create); XmlSerializer xCfg = new XmlSerializer(typeof(CfgDto)); config.UserDao = "default"; config.UserLogic = "default"; config.AwardDao = "default"; config.AwardLogic = "default"; config.WebUserDao = "default"; config.WebUserLogic = "default"; config.ImageDao = "default"; config.ImageDao = "default"; xCfg.Serialize(openCfgStream, config); openCfgStream.Close(); } switch (config.UserDao) { case "db": _uDao = _uDao ?? (_uDao = new DbDAL.UserDao()); break; default: _uDao = _uDao ?? (_uDao = new DAL.UserDao()); break; } switch (config.UserLogic) { default: _uLogic = _uLogic ?? (_uLogic = new UserLogic(_uDao)); break; } switch (config.AwardDao) { case "db": _aDao = _aDao ?? (_aDao = new DbDAL.AwardDao()); break; default: _aDao = _aDao ?? (_aDao = new DAL.AwardDao()); break; } switch (config.AwardLogic) { default: _aLogic = _aLogic ?? (_aLogic = new AwardLogic(_aDao)); break; } switch (config.WebUserDao) { default: _wuDao = _wuDao ?? (_wuDao = new DbDAL.WebUserDao()); break; } switch (config.WebUserLogic) { default: _wuLogic = _wuLogic ?? (_wuLogic = new WebUserLogic(_wuDao)); break; } switch (config.ImageDao) { default: _imDao = _imDao ?? (_imDao = new DbDAL.ImageDao()); break; } switch (config.ImageLogic) { default: _imLogic = _imLogic ?? (_imLogic = new ImageLogic(_imDao)); break; } }