@@ -67,6 +67,9 @@ public static class BindingKeys
6767 public const string AsyncDeleteAccountName = "AsyncDeleteAccountService" ;
6868 public const string SyncDeleteAccountName = "SyncDeleteAccountService" ;
6969
70+ public const string PrimaryStatisticsKey = "PrimaryStatisticsKey" ;
71+ public const string AlternateStatisticsKey = "AlternateStatisticsKey" ;
72+
7073 public const string AccountDeleterTopic = "AccountDeleterBindingKey" ;
7174 public const string PackageValidationTopic = "PackageValidationBindingKey" ;
7275 public const string SymbolsPackageValidationTopic = "SymbolsPackageValidationBindingKey" ;
@@ -698,6 +701,51 @@ private static void RegisterDeleteAccountService(ContainerBuilder builder, Confi
698701 }
699702 }
700703
704+ private static void RegisterStatisticsServices ( ContainerBuilder builder , IGalleryConfigurationService configuration , ITelemetryService telemetryService )
705+ {
706+ // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs
707+ builder . RegisterInstance ( new JsonAggregateStatsService ( configuration . Current . AzureStorage_Statistics_ConnectionString , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
708+ . AsSelf ( )
709+ . As < IAggregateStatsService > ( )
710+ . SingleInstance ( ) ;
711+
712+ // when running on Windows Azure, pull the statistics from the warehouse via storage
713+ builder . RegisterInstance ( new CloudReportService ( configuration . Current . AzureStorage_Statistics_ConnectionString , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
714+ . AsSelf ( )
715+ . As < IReportService > ( )
716+ . SingleInstance ( ) ;
717+
718+ // when running on Windows Azure, download counts come from the downloads.v1.json blob
719+ builder . Register ( c => new SimpleBlobStorageConfiguration ( configuration . Current . AzureStorage_Statistics_ConnectionString , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
720+ . SingleInstance ( )
721+ . Keyed < IBlobStorageConfiguration > ( BindingKeys . PrimaryStatisticsKey ) ;
722+
723+ builder . Register ( c => new SimpleBlobStorageConfiguration ( configuration . Current . AzureStorage_Statistics_ConnectionString_Alternate , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
724+ . SingleInstance ( )
725+ . Keyed < IBlobStorageConfiguration > ( BindingKeys . AlternateStatisticsKey ) ;
726+
727+ builder . Register ( c =>
728+ {
729+ var primaryConfiguration = c . ResolveKeyed < IBlobStorageConfiguration > ( BindingKeys . PrimaryStatisticsKey ) ;
730+ var alternateConfiguration = c . ResolveKeyed < IBlobStorageConfiguration > ( BindingKeys . AlternateStatisticsKey ) ;
731+ var featureFlagService = c . Resolve < IFeatureFlagService > ( ) ;
732+ var downloadCountService = new CloudDownloadCountService ( telemetryService , featureFlagService , primaryConfiguration , alternateConfiguration ) ;
733+
734+ var dlCountInterceptor = new DownloadCountObjectMaterializedInterceptor ( downloadCountService , telemetryService ) ;
735+ ObjectMaterializedInterception . AddInterceptor ( dlCountInterceptor ) ;
736+
737+ return downloadCountService ;
738+ } )
739+ . AsSelf ( )
740+ . As < IDownloadCountService > ( )
741+ . SingleInstance ( ) ;
742+
743+ builder . RegisterType < JsonStatisticsService > ( )
744+ . AsSelf ( )
745+ . As < IStatisticsService > ( )
746+ . SingleInstance ( ) ;
747+ }
748+
701749 private static void RegisterSwitchingDeleteAccountService ( ContainerBuilder builder , ConfigurationService configuration )
702750 {
703751 var asyncAccountDeleteConnectionString = configuration . ServiceBus . AccountDeleter_ConnectionString ;
@@ -1368,34 +1416,7 @@ private static void ConfigureForAzureStorage(ContainerBuilder builder, IGalleryC
13681416 }
13691417 }
13701418
1371- // when running on Windows Azure, we use a back-end job to calculate stats totals and store in the blobs
1372- builder . RegisterInstance ( new JsonAggregateStatsService ( configuration . Current . AzureStorage_Statistics_ConnectionString , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
1373- . AsSelf ( )
1374- . As < IAggregateStatsService > ( )
1375- . SingleInstance ( ) ;
1376-
1377- // when running on Windows Azure, pull the statistics from the warehouse via storage
1378- builder . RegisterInstance ( new CloudReportService ( configuration . Current . AzureStorage_Statistics_ConnectionString , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
1379- . AsSelf ( )
1380- . As < IReportService > ( )
1381- . SingleInstance ( ) ;
1382-
1383- // when running on Windows Azure, download counts come from the downloads.v1.json blob
1384- var downloadCountService = new CloudDownloadCountService (
1385- telemetryService ,
1386- configuration . Current . AzureStorage_Statistics_ConnectionString ,
1387- configuration . Current . AzureStorageReadAccessGeoRedundant ) ;
1388-
1389- builder . RegisterInstance ( downloadCountService )
1390- . AsSelf ( )
1391- . As < IDownloadCountService > ( )
1392- . SingleInstance ( ) ;
1393- ObjectMaterializedInterception . AddInterceptor ( new DownloadCountObjectMaterializedInterceptor ( downloadCountService , telemetryService ) ) ;
1394-
1395- builder . RegisterType < JsonStatisticsService > ( )
1396- . AsSelf ( )
1397- . As < IStatisticsService > ( )
1398- . SingleInstance ( ) ;
1419+ RegisterStatisticsServices ( builder , configuration , telemetryService ) ;
13991420
14001421 builder . RegisterInstance ( new TableErrorLog ( configuration . Current . AzureStorage_Errors_ConnectionString , configuration . Current . AzureStorageReadAccessGeoRedundant ) )
14011422 . As < ErrorLog > ( )
0 commit comments