/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">An instance of <see cref="IServiceCollection"/>.</param> public void ConfigureServices(IServiceCollection services) { this.ConfigureServicesCommon(services); _ = services.AddMvc(); _ = services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "NotificationService", Version = "v1" }); }); ITelemetryInitializer[] itm = new ITelemetryInitializer[1]; var envInitializer = new EnvironmentInitializer { Service = this.Configuration[AIConstants.ServiceConfigName], ServiceLine = this.Configuration[AIConstants.ServiceLineConfigName], ServiceOffering = this.Configuration[AIConstants.ServiceOfferingConfigName], ComponentId = this.Configuration[AIConstants.ComponentIdConfigName], ComponentName = this.Configuration[AIConstants.ComponentNameConfigName], EnvironmentName = this.Configuration[AIConstants.EnvironmentName], IctoId = "IctoId", }; itm[0] = envInitializer; NotificationProviders.Common.Logger.LoggingConfiguration loggingConfiguration = new NotificationProviders.Common.Logger.LoggingConfiguration { IsTraceEnabled = true, TraceLevel = (SeverityLevel)Enum.Parse(typeof(SeverityLevel), this.Configuration[ConfigConstants.AITraceLelelConfigKey]), EnvironmentName = this.Configuration[AIConstants.EnvironmentName], }; var tconfig = TelemetryConfiguration.CreateDefault(); tconfig.InstrumentationKey = this.Configuration[ConfigConstants.AIInsrumentationConfigKey]; DependencyTrackingTelemetryModule depModule = new DependencyTrackingTelemetryModule(); depModule.Initialize(tconfig); RequestTrackingTelemetryModule requestTrackingTelemetryModule = new RequestTrackingTelemetryModule(); requestTrackingTelemetryModule.Initialize(tconfig); _ = services.AddSingleton <NotificationProviders.Common.Logger.ILogger>(_ => new NotificationProviders.Common.Logger.AILogger(loggingConfiguration, tconfig, itm)); _ = services.AddScoped <IEmailManager, EmailManager>(s => new EmailManager( this.Configuration, s.GetService <IRepositoryFactory>(), s.GetService <ILogger>(), s.GetService <IMailTemplateManager>(), s.GetService <ITemplateMerge>())) .AddScoped <IEmailServiceManager, EmailServiceManager>(s => new EmailServiceManager(this.Configuration, s.GetService <IRepositoryFactory>(), s.GetService <ICloudStorageClient>(), s.GetService <ILogger>(), s.GetService <INotificationProviderFactory>(), s.GetService <IEmailManager>())) .AddScoped <ITemplateMerge, TemplateMerge>() .AddSingleton <IEmailAccountManager, EmailAccountManager>() .AddScoped <INotificationProviderFactory, NotificationProviderFactory>(); NotificationProviderType providerType = (NotificationProviderType)Enum.Parse(typeof(NotificationProviderType), this.Configuration[ConfigConstants.NotificationProviderType]); if (NotificationProviderType.DirectSend == providerType) { this.ConfigureDirectSendServices(services); } else if (NotificationProviderType.SMTP == providerType) { this.ConfigureSMTPServices(services); } else { this.ConfigureGraphServices(services); } }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">An instance of <see cref="IServiceCollection"/>.</param> public void ConfigureServices(IServiceCollection services) { this.ConfigureServicesCommon(services); _ = services.AddMvc(); _ = services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "NotificationService", Version = "v1" }); }); ITelemetryInitializer[] itm = new ITelemetryInitializer[1]; var envInitializer = new EnvironmentInitializer { Service = this.Configuration[Constants.ServiceConfigName], ServiceLine = this.Configuration[Constants.ServiceLineConfigName], ServiceOffering = this.Configuration[Constants.ServiceOfferingConfigName], ComponentId = this.Configuration[Constants.ComponentIdConfigName], ComponentName = this.Configuration[Constants.ComponentNameConfigName], EnvironmentName = this.Configuration[Constants.EnvironmentName], IctoId = "IctoId", }; itm[0] = envInitializer; NotificationProviders.Common.Logger.LoggingConfiguration loggingConfiguration = new NotificationProviders.Common.Logger.LoggingConfiguration { IsTraceEnabled = true, TraceLevel = (SeverityLevel)Enum.Parse(typeof(SeverityLevel), this.Configuration["ApplicationInsights:TraceLevel"]), EnvironmentName = this.Configuration[Constants.EnvironmentName], }; var tconfig = TelemetryConfiguration.CreateDefault(); tconfig.InstrumentationKey = this.Configuration["ApplicationInsights:InstrumentationKey"]; DependencyTrackingTelemetryModule depModule = new DependencyTrackingTelemetryModule(); depModule.Initialize(tconfig); RequestTrackingTelemetryModule requestTrackingTelemetryModule = new RequestTrackingTelemetryModule(); requestTrackingTelemetryModule.Initialize(tconfig); _ = services.AddSingleton <NotificationProviders.Common.Logger.ILogger>(_ => new NotificationProviders.Common.Logger.AILogger(loggingConfiguration, tconfig, itm)); _ = services.AddSingleton <SendAccountConfiguration>(new SendAccountConfiguration() { DisplayName = this.Configuration["DirectSendSetting:DisplayName"], }); if (int.TryParse(this.Configuration["DirectSendSetting:SmtpPort"], out int port)) { _ = services.AddSingleton <ISmtpConfiguration>(new SmtpConfiguration() { SmtpPort = port, SmtpServer = this.Configuration["DirectSendSetting:SmtpServer"] }); } _ = services.AddSingleton <ISmtpClientFactory, DSSmtpClientFactory>() .AddSingleton <ISmtpClientPool, SmtpClientPool>() .AddSingleton <IEmailService, DirectSendMailService>(); _ = services.AddScoped <INotificationReportManager, NotificationReportManager>() .AddScoped <IEmailManager, EmailManager>(s => new EmailManager( this.Configuration, s.GetService <IRepositoryFactory>(), s.GetService <ILogger>(), s.GetService <IMailTemplateManager>(), s.GetService <ITemplateMerge>())) .AddScoped <IEmailServiceManager, EmailServiceManager>(s => new EmailServiceManager(this.Configuration, s.GetService <IRepositoryFactory>(), s.GetService <ICloudStorageClient>(), s.GetService <ILogger>(), s.GetService <INotificationProviderFactory>(), s.GetService <IEmailManager>())) .AddScoped <IRepositoryFactory, RepositoryFactory>() .AddScoped <EmailNotificationRepository>() .AddScoped <IEmailNotificationRepository, EmailNotificationRepository>(s => s.GetService <EmailNotificationRepository>()) .AddScoped <TableStorageEmailRepository>() .AddScoped <IEmailNotificationRepository, TableStorageEmailRepository>(s => s.GetService <TableStorageEmailRepository>()) .AddScoped <ITableStorageClient, TableStorageClient>() .AddScoped <IMailTemplateManager, MailTemplateManager>() .AddScoped <IMailTemplateRepository, MailTemplateRepository>() .AddScoped <IMailAttachmentRepository, MailAttachmentRepository>() .AddScoped <ITemplateMerge, TemplateMerge>() .AddSingleton <IEmailAccountManager, EmailAccountManager>() .AddScoped <INotificationProviderFactory, NotificationProviderFactory>() .AddScoped <DirectSendNotificationProvider>(s => new DirectSendNotificationProvider(this.Configuration, s.GetService <IEmailService>(), s.GetService <ILogger>(), s.GetService <IEmailManager>())) .AddScoped <INotificationProvider, DirectSendNotificationProvider>() .AddScoped <MSGraphNotificationProvider>(s => new MSGraphNotificationProvider(this.Configuration, s.GetService <IEmailAccountManager>(), s.GetService <ILogger>(), Options.Create(this.Configuration.GetSection("MSGraphSetting").Get <MSGraphSetting>()), Options.Create(this.Configuration.GetSection("PollyRetrySetting").Get <RetrySetting>()), s.GetService <ITokenHelper>(), s.GetService <IMSGraphProvider>(), s.GetService <IEmailManager>())) .AddScoped <INotificationProvider, MSGraphNotificationProvider>(); }