public static StatisticsDbContext CreateStatisticsDbContext()
        {
            var optionsBuilder = new DbContextOptionsBuilder <StatisticsDbContext>();

            optionsBuilder.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("StatisticsDb"),
                                        providerOptions => providerOptions.EnableRetryOnFailure());

            return(new StatisticsDbContext(optionsBuilder.Options));
        }
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var serviceProvider = builder.Services
                                  .AddDbContext <ContentDbContext>(options =>
                                                                   options.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("ContentDb")))
                                  .AddSingleton <IBlobStorageService, BlobStorageService>(
                provider =>
            {
                var connectionString = GetConfigurationValue(provider, "CoreStorage");

                var blobStorageService = new BlobStorageService(
                    connectionString,
                    new BlobServiceClient(connectionString),
                    provider.GetRequiredService <ILogger <IBlobStorageService> >()
                    );
                return(blobStorageService);
            })
                                  .AddSingleton <IStorageQueueService, StorageQueueService>(provider =>
                                                                                            new StorageQueueService(GetConfigurationValue(provider, "CoreStorage")))
                                  .AddTransient <IFileImportService, FileImportService>()
                                  .AddTransient <IImporterService, ImporterService>()
                                  .AddTransient <ISplitFileService, SplitFileService>()
                                  .AddTransient <ImporterFilterService>()
                                  .AddTransient <ImporterLocationService>()
                                  .AddTransient <IImporterMetaService, ImporterMetaService>()
                                  .AddTransient <ImporterMemoryCache>()
                                  .AddTransient <IBatchService, BatchService>()
                                  .AddTransient <IDataImportService, DataImportService>()
                                  .AddTransient <IValidatorService, ValidatorService>()
                                  .AddSingleton <IDataArchiveService, DataArchiveService>()
                                  .AddSingleton <IFileTypeService, FileTypeService>()
                                  .AddSingleton <IGuidGenerator, SequentialGuidGenerator>()
                                  .AddTransient <IProcessorService, ProcessorService>()
                                  .BuildServiceProvider();

            HandleRestart(serviceProvider.GetRequiredService <IStorageQueueService>());
        }
Beispiel #3
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services
            .AddAutoMapper(typeof(Startup).Assembly)
            .AddMemoryCache()
            .AddDbContext <ContentDbContext>(options =>
                                             options.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("ContentDb")))
            .AddDbContext <StatisticsDbContext>(options =>
                                                options.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("StatisticsDb")))
            .AddDbContext <PublicStatisticsDbContext>(options =>
                                                      options.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("PublicStatisticsDb")))
            .AddSingleton <IFileStorageService, FileStorageService>(provider =>
                                                                    new FileStorageService(GetConfigurationValue(provider, "PublisherStorage")))
            .AddScoped <IBlobCacheService, BlobCacheService>(provider =>
                                                             new BlobCacheService(
                                                                 blobStorageService: GetBlobStorageService(provider, "PublicStorage"),
                                                                 logger: provider.GetRequiredService <ILogger <BlobCacheService> >()))
            .AddScoped <IPublishingService, PublishingService>(provider =>
                                                               new PublishingService(
                                                                   publicStorageConnectionString: GetConfigurationValue(provider, "PublicStorage"),
                                                                   privateBlobStorageService: GetBlobStorageService(provider, "CoreStorage"),
                                                                   publicBlobStorageService: GetBlobStorageService(provider, "PublicStorage"),
                                                                   publicBlobCacheService: provider.GetRequiredService <IBlobCacheService>(),
                                                                   methodologyService: provider.GetRequiredService <IMethodologyService>(),
                                                                   publicationService: provider.GetRequiredService <IPublicationService>(),
                                                                   releaseService: provider.GetRequiredService <IReleaseService>(),
                                                                   logger: provider.GetRequiredService <ILogger <PublishingService> >()))
            .AddScoped <IContentService, ContentService>(provider =>
                                                         new ContentService(
                                                             publicBlobStorageService: GetBlobStorageService(provider, "PublicStorage"),
                                                             blobCacheService: provider.GetService <IBlobCacheService>(),
                                                             fastTrackService: provider.GetService <IFastTrackService>(),
                                                             releaseService: provider.GetRequiredService <IReleaseService>(),
                                                             publicationService: provider.GetRequiredService <IPublicationService>()
                                                             ))
            .AddScoped <IReleaseService, ReleaseService>(provider =>
                                                         new ReleaseService(
                                                             contentDbContext: provider.GetService <ContentDbContext>(),
                                                             statisticsDbContext: provider.GetService <StatisticsDbContext>(),
                                                             publicStatisticsDbContext: provider.GetService <PublicStatisticsDbContext>(),
                                                             publicBlobStorageService: GetBlobStorageService(provider, "PublicStorage"),
                                                             methodologyService: provider.GetService <IMethodologyService>(),
                                                             releaseSubjectRepository: provider.GetService <IReleaseSubjectRepository>(),
                                                             logger: provider.GetRequiredService <ILogger <ReleaseService> >(),
                                                             mapper: provider.GetRequiredService <IMapper>()
                                                             ))
            .AddScoped <ITableStorageService, TableStorageService>(provider =>
                                                                   new TableStorageService(GetConfigurationValue(provider, "PublisherStorage")))
            .AddScoped <IPublicationService, PublicationService>()
            .AddScoped <IFastTrackService, FastTrackService>(provider =>
                                                             new FastTrackService(
                                                                 contentDbContext: provider.GetService <ContentDbContext>(),
                                                                 publicBlobStorageService: GetBlobStorageService(provider, "PublicStorage"),
                                                                 tableStorageService: new TableStorageService(GetConfigurationValue(provider, "PublicStorage"))))
            .AddScoped <IMethodologyVersionRepository, MethodologyVersionRepository>()
            .AddScoped <IMethodologyRepository, MethodologyRepository>()
            .AddScoped <IMethodologyService, MethodologyService>()
            .AddScoped <INotificationsService, NotificationsService>(provider =>
                                                                     new NotificationsService(
                                                                         context: provider.GetService <ContentDbContext>(),
                                                                         storageQueueService: new StorageQueueService(GetConfigurationValue(provider,
                                                                                                                                            "NotificationStorage"))))
            .AddScoped <IQueueService, QueueService>(provider =>
                                                     new QueueService(
                                                         storageQueueService: new StorageQueueService(
                                                             storageConnectionString: GetConfigurationValue(provider, "PublisherStorage")
                                                             ),
                                                         releasePublishingStatusService: provider.GetService <IReleasePublishingStatusService>(),
                                                         logger: provider.GetRequiredService <ILogger <QueueService> >()))
            .AddScoped <IReleasePublishingStatusService, ReleasePublishingStatusService>()
            .AddScoped <IValidationService, ValidationService>()
            .AddScoped <IReleaseSubjectRepository, ReleaseSubjectRepository>(provider =>
                                                                             new ReleaseSubjectRepository(
                                                                                 statisticsDbContext: provider.GetService <PublicStatisticsDbContext>(),
                                                                                 footnoteRepository: new FootnoteRepository(provider.GetService <PublicStatisticsDbContext>())
                                                                                 ))
            .AddScoped <IFilterRepository, FilterRepository>()
            .AddScoped <IFootnoteRepository, FootnoteRepository>()
            .AddScoped <IIndicatorRepository, IndicatorRepository>();

            AddPersistenceHelper <ContentDbContext>(builder.Services);
            AddPersistenceHelper <StatisticsDbContext>(builder.Services);
            AddPersistenceHelper <PublicStatisticsDbContext>(builder.Services);
        }
Beispiel #4
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services
            .AddAutoMapper(typeof(Startup).Assembly)
            .AddMemoryCache()
            .AddDbContext <ContentDbContext>(options =>
                                             options.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("ContentDb")))
            .AddDbContext <StatisticsDbContext>(options =>
                                                options.UseSqlServer(ConnectionUtils.GetAzureSqlConnectionString("StatisticsDb")))
            .AddSingleton <IFileStorageService, FileStorageService>(
                provider =>
            {
                var privateStorageConnectionString   = GetConfigurationValue(provider, "CoreStorage");
                var publicStorageConnectionString    = GetConfigurationValue(provider, "PublicStorage");
                var publisherStorageConnectionString = GetConfigurationValue(provider, "PublisherStorage");

                var privateBlobStorageService = new BlobStorageService(
                    privateStorageConnectionString,
                    new BlobServiceClient(privateStorageConnectionString),
                    provider.GetRequiredService <ILogger <BlobStorageService> >());

                var publicBlobStorageService = new BlobStorageService(
                    publicStorageConnectionString,
                    new BlobServiceClient(publicStorageConnectionString),
                    provider.GetRequiredService <ILogger <BlobStorageService> >());

                var publisherBlobStorageService = new BlobStorageService(
                    publicStorageConnectionString,
                    new BlobServiceClient(publisherStorageConnectionString),
                    provider.GetRequiredService <ILogger <BlobStorageService> >());

                return(new FileStorageService(
                           privateBlobStorageService: privateBlobStorageService,
                           publicBlobStorageService: publicBlobStorageService,
                           publicStorageConnectionString: publicStorageConnectionString,
                           publisherStorageConnectionString: publisherStorageConnectionString,
                           logger: provider.GetRequiredService <ILogger <FileStorageService> >()));
            })
            .AddScoped <IPublishingService, PublishingService>()
            .AddScoped <IContentService, ContentService>()
            .AddScoped <ITaxonomyService, TaxonomyService>()
            .AddScoped <IReleaseService, ReleaseService>()
            .AddScoped <ITableStorageService, TableStorageService>(provider =>
                                                                   new TableStorageService(GetConfigurationValue(provider, "PublisherStorage")))
            .AddScoped <IPublicationService, PublicationService>()
            .AddScoped <IDownloadService, DownloadService>()
            .AddScoped <IFastTrackService, FastTrackService>(provider =>
                                                             new FastTrackService(provider.GetService <ContentDbContext>(),
                                                                                  provider.GetService <IFileStorageService>(),
                                                                                  new TableStorageService(GetConfigurationValue(provider, "PublicStorage"))))
            .AddScoped <IMethodologyService, MethodologyService>()
            .AddScoped <INotificationsService, NotificationsService>(provider =>
                                                                     new NotificationsService(provider.GetService <ContentDbContext>(),
                                                                                              new StorageQueueService(GetConfigurationValue(provider, "NotificationStorage"))))
            .AddScoped <IQueueService, QueueService>(provider => new QueueService(
                                                         new StorageQueueService(GetConfigurationValue(provider, "PublisherStorage")),
                                                         provider.GetService <IReleaseStatusService>(),
                                                         provider.GetRequiredService <ILogger <QueueService> >()))
            .AddScoped <IReleaseStatusService, ReleaseStatusService>()
            .AddScoped <IValidationService, ValidationService>()
            .AddScoped <IReleaseSubjectService, ReleaseSubjectService>()
            .AddScoped <IFootnoteRepository, FootnoteRepository>();
        }