public static IServiceProvider Initialize( IServiceCollection services, string connectionString, ICacheStore cacheStore, IEmailSender emailSender, EmailsSettings emailsSettings, ILogger logger, IExecutionContextAccessor executionContextAccessor, bool runQuartz = true) { if (runQuartz) { StartQuartz(connectionString, emailsSettings, logger, executionContextAccessor); } services.AddSingleton(cacheStore); var serviceProvider = CreateAutofacServiceProvider( services, connectionString, emailSender, emailsSettings, logger, executionContextAccessor); return(serviceProvider); }
private static IServiceProvider CreateAutofacServiceProvider( IServiceCollection services, string connectionString, IEmailSender emailSender, EmailsSettings emailsSettings) { var container = new ContainerBuilder(); container.Populate(services); container.RegisterModule(new DataAccessModule(connectionString)); container.RegisterModule(new MediatorModule()); container.RegisterModule(new DomainModule()); if (emailSender != null) { container.RegisterModule(new EmailModule(emailSender, emailsSettings)); } else { container.RegisterModule(new EmailModule(emailsSettings)); } container.RegisterModule(new ProcessingModule()); var buildContainer = container.Build(); ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(buildContainer)); var serviceProvider = new AutofacServiceProvider(buildContainer); CompositionRoot.SetContainer(buildContainer); return(serviceProvider); }
public async Task BeforeEachTest() { const string connectionStringEnvironmentVariable = "ASPNETCORE_SampleProject_IntegrationTests_ConnectionString"; ConnectionString = Environment.GetEnvironmentVariable(connectionStringEnvironmentVariable); if (ConnectionString == null) { throw new ApplicationException( $"Define connection string to integration tests database using environment variable: {connectionStringEnvironmentVariable}"); } await using var sqlConnection = new SqlConnection(ConnectionString); await ClearDatabase(sqlConnection); EmailsSettings = new EmailsSettings { FromAddressEmail = "*****@*****.**" }; EmailSender = Substitute.For <IEmailSender>(); ApplicationStartup.Initialize( new ServiceCollection(), ConnectionString, new CacheStore(), EmailSender, EmailsSettings, runQuartz: false); }
private static void StartQuartz( string connectionString, EmailsSettings emailsSettings, AzureBlobStorageSettings blobStorageSettings, ILogger logger, IExecutionContextAccessor executionContextAccessor, IUserAuthIdProvider userAuthIdProvider) { var schedulerFactory = new StdSchedulerFactory(); var scheduler = schedulerFactory.GetScheduler().GetAwaiter().GetResult(); var container = new ContainerBuilder(); container.RegisterModule(new LoggingModule(logger)); container.RegisterModule(new QuartzModule()); container.RegisterModule(new MediatorModule()); container.RegisterModule(new DataAccessModule(connectionString)); container.RegisterModule(new EmailModule(emailsSettings)); container.RegisterModule(new ProcessingModule()); container.RegisterModule(new AuthenticationModule(userAuthIdProvider)); container.RegisterModule(new AzureBlobStorageModule(blobStorageSettings)); container.RegisterInstance(executionContextAccessor); container.Register(c => { var dbContextOptionsBuilder = new DbContextOptionsBuilder <TreesContext>(); dbContextOptionsBuilder.UseSqlServer(connectionString); dbContextOptionsBuilder .ReplaceService <IValueConverterSelector, StronglyTypedIdValueConverterSelector>(); return(new TreesContext(dbContextOptionsBuilder.Options)); }).AsSelf().InstancePerLifetimeScope(); scheduler.JobFactory = new JobFactory(container.Build()); scheduler.Start().GetAwaiter().GetResult(); var processOutboxJob = JobBuilder.Create <ProcessOutboxJob>().Build(); var trigger = TriggerBuilder .Create() .StartNow() .WithCronSchedule("0/15 * * ? * *") .Build(); scheduler.ScheduleJob(processOutboxJob, trigger).GetAwaiter().GetResult(); var processInternalCommandsJob = JobBuilder.Create <ProcessInternalCommandsJob>().Build(); var triggerCommandsProcessing = TriggerBuilder .Create() .StartNow() .WithCronSchedule("0/15 * * ? * *") .Build(); scheduler.ScheduleJob(processInternalCommandsJob, triggerCommandsProcessing).GetAwaiter().GetResult(); }
public SendConfirmationEmail_Brasseler(Lazy <IBuildEmailValues> buildEmailValues, Lazy <IEmailService> emailService, IEmailTemplateUtilities emailTemplateUtilities, IContentManagerUtilities contentManagerUtilities, EmailsSettings emailsSettings) { this.buildEmailValues = buildEmailValues; this.EmailTemplateUtilities = emailTemplateUtilities; this.EmailService = emailService; this.ContentManagerUtilities = contentManagerUtilities; this.EmailsSettings = emailsSettings; customSettings = new CustomSettings(); }
public OrderPlacedNotificationHandler( IEmailSender emailSender, EmailsSettings emailsSettings, ISqlConnectionFactory sqlConnectionFactory) { _emailSender = emailSender; _emailsSettings = emailsSettings; _sqlConnectionFactory = sqlConnectionFactory; }
public ChangeStatusToAwaitingApproval_Brasseler(Lazy <ICookieManager> cookieManager, ICurrencyFormatProvider currencyFormatProvider, Lazy <ICustomerOrderUtilities> customerOrderUtilities, IUnitOfWorkFactory unitOfWorkFactory, IContentManagerUtilities contentManagerUtilities, IEmailService emailService, EmailsSettings emailsSettings, IEmailTemplateUtilities emailTemplateUtilities, IOrderLineUtilities OrderLineUtilities, Lazy <ITranslationLocalizer> translationLocalizer) { this.cookieManager = cookieManager; this.CurrencyFormatProvider = currencyFormatProvider; this.CustomerOrderUtilities = customerOrderUtilities; this.UnitOfWork = unitOfWorkFactory.GetUnitOfWork(); this.ContentManagerUtilities = contentManagerUtilities; this.EmailService = emailService; customSettings = new CustomSettings(); this.EmailsSettings = emailsSettings; this.EmailTemplateUtilities = emailTemplateUtilities; this.OrderLineUtilities = OrderLineUtilities; this.TranslationLocalizer = translationLocalizer; }
public ApplicationFixture() { const string connectionStringEnvironmentVariable = "ASPNETCORE_TreeOfAKind_IntegrationTests_ConnectionString"; ConnectionString = Environment.GetEnvironmentVariable(connectionStringEnvironmentVariable); if (ConnectionString == null) { throw new ApplicationException( $"Define connection string to integration tests database using environment variable: {connectionStringEnvironmentVariable}"); } using var sqlConnection = new SqlConnection(ConnectionString); ClearDatabase(sqlConnection); EmailsSettings = new EmailsSettings { FromAddressEmail = "*****@*****.**" }; AzureBlobStorageSettings = new AzureBlobStorageSettings { ConnectionString = "someConnectionString", Metadata = new Dictionary <string, string> { { "IntegrationTesting", "true" } } }; EmailSender = Substitute.For <IEmailSender>(); FileSaver = Substitute.For <IFileSaver>(); UserAuthIdProvider = Substitute.For <IUserAuthIdProvider>(); ExecutionContext = new ExecutionContextMock(); ApplicationStartup.Initialize( new ServiceCollection(), ConnectionString, new CacheStore(), EmailSender, FileSaver, EmailsSettings, AzureBlobStorageSettings, Logger.None, ExecutionContext, UserAuthIdProvider, runQuartz: false); }
public EmailService_Brasseler(IEmailTemplateUtilities emailTemplateUtilities, IContentManagerUtilities contentManagerUtilities, IEntityTranslationService entityTranslationService, EmailsSettings emailsSettings, Lazy <IEmailTemplateRenderer> emailTemplateRenderer, Lazy <IPerRequestCacheManager> perRequestCacheManager) : base(emailTemplateUtilities, contentManagerUtilities, entityTranslationService, emailsSettings, emailTemplateRenderer, perRequestCacheManager) { this.CustomSettings = new CustomSettings(); }
private static IServiceProvider CreateAutofacServiceProvider( IServiceCollection services, string connectionString, IEmailSender emailSender, IFileSaver fileSaver, EmailsSettings emailsSettings, AzureBlobStorageSettings azureBlobStorageSettings, ILogger logger, IExecutionContextAccessor executionContextAccessor, IUserAuthIdProvider userAuthIdProvider) { var container = new ContainerBuilder(); container.Populate(services); container.RegisterModule(new LoggingModule(logger)); container.RegisterModule(new DataAccessModule(connectionString)); container.RegisterModule(new MediatorModule()); container.RegisterModule(new DomainModule()); container.RegisterModule(new GedcomXToDomainModule()); container.RegisterModule(new AuthenticationModule(userAuthIdProvider)); container.RegisterModule(new AzureBlobStorageModule(azureBlobStorageSettings, fileSaver)); if (emailSender != null) { container.RegisterModule(new EmailModule(emailSender, emailsSettings)); } else { container.RegisterModule(new EmailModule(emailsSettings)); } container.RegisterModule(new ProcessingModule()); container.RegisterInstance(executionContextAccessor); var buildContainer = container.Build(); ServiceLocator.SetLocatorProvider(() => new AutofacServiceLocator(buildContainer)); var serviceProvider = new AutofacServiceProvider(buildContainer); CompositionRoot.SetContainer(buildContainer); return(serviceProvider); }
public async Task <IActionResult> ResetPasswordEmail(ResetPasswordEmail emailModel) { if (ModelState.IsValid) { var user = _uow.UsersRepository.Get(ent => ent.Email == emailModel.Email); if (user != null) { var log = new ForgetPasswordURL(); log.ToId = user.Id; log.ToType = (int)EN_TypeUser.User; log.Token = Guid.NewGuid(); log.Expiration = DateTime.Now.AddMinutes(30); _uow.ForgetPasswordURLRepository.Add(log); _uow.Save(); var subject = "Reset Password Confirmation Email"; string url1 = $"{AppSession.AppURL}Account/ResetPassword?token={ log.Token }"; var model = new EmailModelsResetPass(); model.Url = url1; string htmlbody = await _razorViewToStringRenderer.RenderViewToStringAsync("/Views/Emails/_ResetPasswordEmail.cshtml", model); var emailsendstatus = EmailsSettings.EmailSend(user.EnglishName, user.Email, subject, htmlbody); if (!emailsendstatus) { ModelState.AddModelError("Email", "Error Occured While Send Email!!"); } else { return(RedirectToAction("ResetPasswordDone", "Account")); } } else { ModelState.AddModelError("Email", "No Email Found Match Entered Email"); } } return(View(emailModel)); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddMemoryCache(); services.AddSwaggerDocumentation(); services.AddProblemDetails(x => { x.Map <InvalidCommandException>(ex => new InvalidCommandProblemDetails(ex)); x.Map <BusinessRuleValidationException>(ex => new BusinessRuleValidationExceptionProblemDetails(ex)); }); services.AddHttpContextAccessor(); ServiceProvider serviceProvider = services.BuildServiceProvider(); IExecutionContextAccessor executionContextAccessor = new ExecutionContextAccessor(serviceProvider.GetService <IHttpContextAccessor>()); IEnumerable <IConfigurationSection> children = _configuration.GetSection("Caching").GetChildren(); Dictionary <string, TimeSpan> cachingConfiguration = children.ToDictionary(child => child.Key, child => TimeSpan.Parse(child.Value)); EmailsSettings emailsSettings = _configuration.GetSection("EmailsSettings").Get <EmailsSettings>(); IMemoryCache memoryCache = serviceProvider.GetService <IMemoryCache>(); return(ApplicationStartup.Initialize( services, _configuration[OrdersConnectionString], new MemoryCacheStore(memoryCache, cachingConfiguration), null, emailsSettings, _logger, executionContextAccessor)); }
public EmailModule(IEmailSender emailSender, EmailsSettings emailsSettings) { _emailSender = emailSender; _emailsSettings = emailsSettings; }
public EmailSender(EmailsSettings emailsSettings) { this._emailsSettings = emailsSettings; }
internal EmailModule(EmailsSettings emailsSettings) { _emailsSettings = emailsSettings; }
internal EmailModule(IEmailSender emailSender, EmailsSettings emailsSettings) { _emailSender = emailSender; _emailsSettings = emailsSettings; }
public EmailSender(EmailsSettings emailsSettings, ILogger logger) { _emailsSettings = emailsSettings; _logger = logger; }
public async Task <IActionResult> CustomerResetPasswordEmail(ResetPasswordEmail emailModel) { if (ModelState.IsValid) { var customer = _uow.CustomerRepository.Get(ent => ent.Email == emailModel.Email); if (customer != null) { var log = new ForgetPasswordURL(); log.ToId = customer.Id; log.ToType = (int)EN_TypeUser.Customer; log.Token = Guid.NewGuid(); log.Expiration = DateTime.Now.AddMinutes(30); _uow.ForgetPasswordURLRepository.Add(log); _uow.Save(); var subject = "Reset Password Confirmation Email"; string url1 = $"{AppSession.AppURL}Account/ResetPassword?token={ log.Token }"; var model = new EmailModelsResetPass(); model.Url = url1; string htmlbody = await _razorViewToStringRenderer.RenderViewToStringAsync("/Views/Emails/_ResetPasswordEmail.cshtml", model); var emailsendstatus = EmailsSettings.EmailSend(customer.EnglishName, customer.Email, subject, htmlbody); if (!emailsendstatus) { ModelState.AddModelError("Email", "Error Occured While Send Email!!"); } else { return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Success, Message = "Reset Password Email Sent Check Your Email", Data = null, Errors = null })); } } else { ModelState.AddModelError("Email", "No Email Found Match Entered Email"); } } var errors = ModelState.Select(ent => new { key = ent.Key, value = ent.Value.Errors.Select(err => (err.ErrorMessage == null || err.ErrorMessage == "") ? err.Exception.Message : err.ErrorMessage) }); var errors_list = new List <string>(); foreach (var sublist in errors) { foreach (var item in sublist.value) { errors_list.Add(sublist.key + ": " + item); } } return(Ok(new ApiResponseModel { Status = EN_ResponseStatus.Faild, Message = "Error Occured", Data = null, Errors = errors_list.ToArray() })); }
public EmailModule(EmailsSettings emailsSettings) { _emailsSettings = emailsSettings; }