static void Main() { var userRepository = new InMemoryUserRepository(); var hotelRepository = new InMemoryHotelRepository(); var smsMessenger = new SmsMessenger(); var emailMessenger = new EmailMessenger(); var users = new User[] { new User("Juanma", smsMessenger, new int[] { 1, 2, 3, 4 }, hotelRepository), new User("Alberto", smsMessenger, new int[] { 1, 3, 5, 7 }, hotelRepository), new User("Emma", emailMessenger, new int[] { 2, 4, 6, 8 }, hotelRepository), new User("Maria", emailMessenger, new int[] { 1, 3, 4, 7, 8 }, hotelRepository) }; foreach (var user in users) { userRepository.Insert(user); } var s = new PromotionSender(userRepository, hotelRepository); s.SendPromotionToEveryone(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //---------------------------------------------------- IConfigService configService = new XMLConfigService("Config.xml"); IMessenger messenger_sms = new SmsMessenger(); IMessenger messenger_email = new EmailMessenger(); IPassHasher passHasher = new SHA256Hasher(); IKeyGenerator smallKeyGenerator = new SmallKeyGenerator(); IKeyGenerator bigKeyGenerator = new BigKeyGenerator(); IRegValidator regValidator = new RegValidator(); IUOWFactory UOWFactory = new EFUOWFactory(configService.ConnectionString); IGetUserDTO getUserDTO = new GetUserDTO(); //---------------------------------------------------- IClaimService claimService = new ClaimService(UOWFactory); //---------------------------------------------------- services.AddSingleton <IConfigService, IConfigService>( serviceProvider => { return(configService); } ); //---------------------------------------------------- services.AddSingleton <IGetUserDTO, IGetUserDTO>( serviceProvider => { return(getUserDTO); } ); //---------------------------------------------------- services.AddSingleton <IUOWFactory, IUOWFactory>( serviceProvider => { return(UOWFactory); } ); services.AddSingleton <IClaimService, ClaimService>(); //----------------------------------------------------- services.AddSingleton <IUserService, UserAuthService>( serviceProvider => { return(new UserAuthService( UOWFactory, new AuthKeyService(smallKeyGenerator, messenger_sms), new AuthKeyService(smallKeyGenerator, messenger_email), passHasher, regValidator, claimService, bigKeyGenerator, getUserDTO )); } ); services.AddSingleton <IProfileService, ProfileService>( serviceProvider => { IConfirmService emailCS = new ConfirmService( new ConfirmKeyService(bigKeyGenerator, messenger_email) ); IConfirmService phoneCS = new ConfirmService( new ConfirmKeyService(smallKeyGenerator, messenger_sms) ); return(new ProfileService( UOWFactory, regValidator, emailCS, phoneCS, passHasher, claimService, getUserDTO )); } ); services.AddSingleton <IRestorePasswordService, RestorePasswordService>( serviceProvider => { var emaiCKS = new ConfirmKeyService(bigKeyGenerator, messenger_email); var phoneCKS = new ConfirmKeyService(smallKeyGenerator, messenger_sms); return(new RestorePasswordService(UOWFactory, emaiCKS, phoneCKS, new RegValidator(), passHasher)); } ); //---------Forum Services-------------------------------- IGroupRules groupRules = new GroupRules(); ISectionRules sectionRules = new SectionRules(groupRules); IThemeRules themeRules = new ThemeRules(sectionRules); IMessageRules messageRules = new MessageRules(themeRules, sectionRules); IDTOHelper dtoHelper = new DTOHelper(); IForumDTOHelper forumDTOHelper = new ForumDTOHelper(messageRules, themeRules, sectionRules, groupRules, dtoHelper); services.AddSingleton <IGroupService, GroupService>( serviceProvider => { return(new GroupService(groupRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <ISectionService, SectionService>( serviceProvider => { return(new SectionService(sectionRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <IThemeService, ThemeService>( serviceProvider => { return(new ThemeService(themeRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <IMessageService, MessageService>( serviceProvider => { return(new MessageService(messageRules, getUserDTO, UOWFactory, forumDTOHelper)); } ); services.AddSingleton <IForumService, ForumService>( serviceProvider => { return(new ForumService(getUserDTO, UOWFactory, forumDTOHelper, groupRules)); } ); //--------------------Page Services-------------------- IPageRules pageRules = new PageRules(); INoteRules noteRules = new NoteRules(); services.AddSingleton <IPageService, PageService>( serviceProvider => { return(new PageService(pageRules, UOWFactory, getUserDTO, dtoHelper)); } ); services.AddSingleton <IBlogService, BlogService>( serviceProvider => { return(new BlogService(noteRules, UOWFactory, getUserDTO, dtoHelper)); } ); //------------------------------------------------------- services.AddSingleton <IImageService, ImageService>( serviceProvider => { return(new ImageService(UOWFactory, getUserDTO)); } ); //------------------------------------------- services.AddSingleton <IAdminService, AdminService>( serviceProvider => { return(new AdminService(getUserDTO, UOWFactory)); } ); services.Configure <FormOptions>(x => { x.ValueCountLimit = int.MaxValue; x.MemoryBufferThreshold = int.MaxValue; x.ValueLengthLimit = int.MaxValue; x.MultipartBodyLengthLimit = int.MaxValue; // In case of multipart }); //------------------------------------------------------ services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/Account/Login"); options.LogoutPath = new Microsoft.AspNetCore.Http.PathString("/Account/Logout"); options.Events.OnValidatePrincipal = PrincipalValidator.ValidateAsync; }); services.AddMvc(); }