public LuceneIndexingJob(TimeSpan frequence, Func <EntitiesContext> contextThunk, TimeSpan timeout, LuceneIndexLocation location)
            : base("Lucene", frequence, timeout)
        {
            _updateIndex = () =>
            {
                using (var context = contextThunk())
                {
                    var indexingService = new LuceneIndexingService(
                        new EntityRepository <Package>(context),
                        new EntityRepository <CuratedPackageVersion>(context),
                        LuceneCommon.GetDirectory(location),
                        null);
                    indexingService.UpdateIndex();
                }
            };

            // Updates the index synchronously first time job is created.
            // For startup code resiliency, we should handle exceptions for the database being down.
            try
            {
                _updateIndex();
            }
            catch (SqlException e)
            {
                QuietLog.LogHandledException(e);
            }
            catch (DataException e)
            {
                QuietLog.LogHandledException(e);
            }
        }
        protected static void UpdateIndexRefreshTime()
        {
            var metadataPath = LuceneCommon.GetIndexMetadataPath();

            if (File.Exists(metadataPath))
            {
                File.SetCreationTimeUtc(metadataPath, DateTime.UtcNow);
            }
        }
        private SearchResults SearchCore(SearchFilter searchFilter)
        {
            // Get index timestamp
            DateTime timestamp = File.GetLastWriteTimeUtc(LuceneCommon.GetIndexMetadataPath());

            int numRecords = searchFilter.Skip + searchFilter.Take;

            var searcher = new IndexSearcher(_directory, readOnly: true);
            var query    = ParseQuery(searchFilter.SearchTerm);

            // IF searching by relevance, boost scores by download count.
            if (searchFilter.SortOrder == SortOrder.Relevance)
            {
                var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
                query = new CustomScoreQuery(query, downloadCountBooster);
            }

            string filterTerm;

            if (SemVerLevelKey.ForSemVerLevel(searchFilter.SemVerLevel) == SemVerLevelKey.SemVer2)
            {
                filterTerm = searchFilter.IncludePrerelease ? "IsLatestSemVer2" : "IsLatestStableSemVer2";
            }
            else
            {
                filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
            }

            Query filterQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));

            if (searchFilter.CuratedFeed != null)
            {
                var          feedFilterQuery  = new TermQuery(new Term("CuratedFeedKey", searchFilter.CuratedFeed.Key.ToString(CultureInfo.InvariantCulture)));
                BooleanQuery conjunctionQuery = new BooleanQuery();
                conjunctionQuery.Add(filterQuery, Occur.MUST);
                conjunctionQuery.Add(feedFilterQuery, Occur.MUST);
                filterQuery = conjunctionQuery;
            }

            Filter filter  = new QueryWrapperFilter(filterQuery);
            var    results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(GetSortField(searchFilter)));

            if (results.TotalHits == 0 || searchFilter.CountOnly)
            {
                return(new SearchResults(results.TotalHits, timestamp));
            }

            var packages = results.ScoreDocs
                           .Skip(searchFilter.Skip)
                           .Select(sd => PackageFromDoc(searcher.Doc(sd.Doc)))
                           .ToList();

            return(new SearchResults(
                       results.TotalHits,
                       timestamp,
                       packages.AsQueryable()));
        }
        public virtual Task <DateTime?> GetLastWriteTime()
        {
            var metadataPath = LuceneCommon.GetIndexMetadataPath();

            if (!File.Exists(metadataPath))
            {
                return(Task.FromResult <DateTime?>(null));
            }
            return(Task.FromResult <DateTime?>(File.GetLastWriteTimeUtc(metadataPath)));
        }
Exemple #5
0
        public virtual DateTime?GetLastWriteTime()
        {
            var metadataPath = LuceneCommon.GetIndexMetadataPath();

            if (!File.Exists(metadataPath))
            {
                return(null);
            }
            return(File.GetLastWriteTimeUtc(metadataPath));
        }
        protected internal static bool IndexRequiresRefresh()
        {
            var metadataPath = LuceneCommon.GetIndexMetadataPath();

            if (File.Exists(metadataPath))
            {
                var creationTime = File.GetCreationTimeUtc(metadataPath);
                return((DateTime.UtcNow - creationTime) > IndexRecreateInterval);
            }

            // If we've never created the index, it needs to be refreshed.
            return(true);
        }
        protected internal virtual void UpdateLastWriteTime()
        {
            var metadataPath = LuceneCommon.GetIndexMetadataPath();

            if (!File.Exists(metadataPath))
            {
                // Create the index and add a timestamp to it that specifies the time at which it was created.
                File.WriteAllBytes(metadataPath, new byte[0]);
            }
            else
            {
                File.SetLastWriteTimeUtc(metadataPath, DateTime.UtcNow);
            }
        }
Exemple #8
0
        public LuceneIndexingJob(TimeSpan frequence, Func <EntitiesContext> contextThunk, TimeSpan timeout)
            : base("Lucene", frequence, timeout)
        {
            _indexingService = new LuceneIndexingService(
                new PackageSource(contextThunk()),
                LuceneCommon.GetDirectory());

            // Updates the index synchronously first time job is created.
            // For startup code resiliency, we should handle exceptions for the database being down.
            try
            {
                _indexingService.UpdateIndex();
            }
            catch (SqlException e)
            {
                QuietLog.LogHandledException(e);
            }
            catch (DataException e)
            {
                QuietLog.LogHandledException(e);
            }
        }
        protected override void Load(ContainerBuilder builder)
        {
            var configuration = new ConfigurationService();

            builder.RegisterInstance(configuration)
            .AsSelf()
            .As <PoliteCaptcha.IConfigurationSource>();
            builder.Register(c => configuration.Current)
            .AsSelf()
            .As <IAppConfiguration>();

            builder.RegisterInstance(LuceneCommon.GetDirectory(configuration.Current.LuceneIndexLocation))
            .As <Lucene.Net.Store.Directory>()
            .SingleInstance();

            ConfigureSearch(builder, configuration);

            if (!string.IsNullOrEmpty(configuration.Current.AzureStorageConnectionString))
            {
                builder.RegisterInstance(new TableErrorLog(configuration.Current.AzureStorageConnectionString))
                .As <ErrorLog>()
                .SingleInstance();
            }
            else
            {
                builder.RegisterInstance(new SqlErrorLog(configuration.Current.SqlConnectionString))
                .As <ErrorLog>()
                .SingleInstance();
            }

            builder.RegisterType <HttpContextCacheService>()
            .AsSelf()
            .As <ICacheService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ContentService>()
            .AsSelf()
            .As <IContentService>()
            .SingleInstance();

            builder.Register(c => new EntitiesContext(configuration.Current.SqlConnectionString, readOnly: configuration.Current.ReadOnlyMode))
            .AsSelf()
            .As <IEntitiesContext>()
            .As <DbContext>()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <User> >()
            .AsSelf()
            .As <IEntityRepository <User> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <CuratedFeed> >()
            .AsSelf()
            .As <IEntityRepository <CuratedFeed> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <CuratedPackage> >()
            .AsSelf()
            .As <IEntityRepository <CuratedPackage> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageRegistration> >()
            .AsSelf()
            .As <IEntityRepository <PackageRegistration> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Package> >()
            .AsSelf()
            .As <IEntityRepository <Package> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDependency> >()
            .AsSelf()
            .As <IEntityRepository <PackageDependency> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageStatistics> >()
            .AsSelf()
            .As <IEntityRepository <PackageStatistics> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDelete> >()
            .AsSelf()
            .As <IEntityRepository <PackageDelete> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Credential> >()
            .AsSelf()
            .As <IEntityRepository <Credential> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageOwnerRequest> >()
            .AsSelf()
            .As <IEntityRepository <PackageOwnerRequest> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <CuratedFeedService>()
            .AsSelf()
            .As <ICuratedFeedService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <UserService>()
            .AsSelf()
            .As <IUserService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageService>()
            .AsSelf()
            .As <IPackageService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageDeleteService>()
            .AsSelf()
            .As <IPackageDeleteService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <EditPackageService>()
            .AsSelf()
            .InstancePerLifetimeScope();

            builder.RegisterType <FormsAuthenticationService>()
            .As <IFormsAuthenticationService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <CookieTempDataProvider>()
            .As <ITempDataProvider>()
            .InstancePerLifetimeScope();

            builder.RegisterType <NuGetExeDownloaderService>()
            .AsSelf()
            .As <INuGetExeDownloaderService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <StatusService>()
            .AsSelf()
            .As <IStatusService>()
            .InstancePerLifetimeScope();

            var mailSenderThunk = new Lazy <IMailSender>(
                () =>
            {
                var settings = configuration;
                if (settings.Current.SmtpUri != null && settings.Current.SmtpUri.IsAbsoluteUri)
                {
                    var smtpUri = new SmtpUri(settings.Current.SmtpUri);

                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        Host           = smtpUri.Host,
                        Port           = smtpUri.Port,
                        EnableSsl      = smtpUri.Secure
                    };

                    if (!string.IsNullOrWhiteSpace(smtpUri.UserName))
                    {
                        mailSenderConfiguration.UseDefaultCredentials = false;
                        mailSenderConfiguration.Credentials           = new NetworkCredential(
                            smtpUri.UserName,
                            smtpUri.Password);
                    }

                    return(new MailSender(mailSenderConfiguration));
                }
                else
                {
                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory,
                        PickupDirectoryLocation = HostingEnvironment.MapPath("~/App_Data/Mail")
                    };

                    return(new MailSender(mailSenderConfiguration));
                }
            });



            builder.Register(c => mailSenderThunk.Value)
            .AsSelf()
            .As <IMailSender>()
            .InstancePerLifetimeScope();

            builder.RegisterType <MessageService>()
            .AsSelf()
            .As <IMessageService>()
            .InstancePerLifetimeScope();

            builder.Register(c => HttpContext.Current.User)
            .AsSelf()
            .As <IPrincipal>()
            .InstancePerLifetimeScope();

            switch (configuration.Current.StorageType)
            {
            case StorageType.FileSystem:
            case StorageType.NotSpecified:
                ConfigureForLocalFileSystem(builder);
                break;

            case StorageType.AzureStorage:
                ConfigureForAzureStorage(builder, configuration);
                break;
            }

            builder.RegisterType <FileSystemService>()
            .AsSelf()
            .As <IFileSystemService>()
            .SingleInstance();

            builder.RegisterType <PackageFileService>()
            .AsSelf()
            .As <IPackageFileService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <UploadFileService>()
            .AsSelf()
            .As <IUploadFileService>()
            .InstancePerLifetimeScope();

            // todo: bind all package curators by convention
            builder.RegisterType <WebMatrixPackageCurator>()
            .AsSelf()
            .As <IAutomaticPackageCurator>()
            .InstancePerLifetimeScope();

            builder.RegisterType <Windows8PackageCurator>()
            .AsSelf()
            .As <IAutomaticPackageCurator>()
            .InstancePerLifetimeScope();

            // todo: bind all commands by convention
            builder.RegisterType <AutomaticallyCuratePackageCommand>()
            .AsSelf()
            .As <IAutomaticallyCuratePackageCommand>()
            .InstancePerLifetimeScope();

            ConfigureAutocomplete(builder, configuration);

            builder.RegisterType <DiagnosticsService>()
            .AsSelf()
            .As <IDiagnosticsService>()
            .SingleInstance();
        }
        protected override void Load(ContainerBuilder builder)
        {
            var telemetryClient = TelemetryClientWrapper.Instance;

            builder.RegisterInstance(telemetryClient)
            .AsSelf()
            .As <ITelemetryClient>()
            .SingleInstance();

            var diagnosticsService = new DiagnosticsService(telemetryClient);

            builder.RegisterInstance(diagnosticsService)
            .AsSelf()
            .As <IDiagnosticsService>()
            .SingleInstance();

            var configuration = new ConfigurationService(new SecretReaderFactory(diagnosticsService));

            UrlExtensions.SetConfigurationService(configuration);

            builder.RegisterInstance(configuration)
            .AsSelf()
            .As <PoliteCaptcha.IConfigurationSource>();

            builder.RegisterInstance(configuration)
            .AsSelf()
            .As <IGalleryConfigurationService>();

            builder.Register(c => configuration.Current)
            .AsSelf()
            .As <IAppConfiguration>();

            // Force the read of this configuration, so it will be initialized on startup
            builder.Register(c => configuration.Features)
            .AsSelf()
            .As <FeatureConfiguration>();

            builder.Register(c => configuration.PackageDelete)
            .As <IPackageDeleteConfiguration>();

            builder.RegisterType <TelemetryService>().As <ITelemetryService>().SingleInstance();
            builder.RegisterType <CredentialBuilder>().As <ICredentialBuilder>().SingleInstance();
            builder.RegisterType <CredentialValidator>().As <ICredentialValidator>().SingleInstance();

            builder.RegisterInstance(LuceneCommon.GetDirectory(configuration.Current.LuceneIndexLocation))
            .As <Lucene.Net.Store.Directory>()
            .SingleInstance();

            ConfigureSearch(builder, configuration);

            builder.RegisterType <DateTimeProvider>().AsSelf().As <IDateTimeProvider>().SingleInstance();

            builder.RegisterType <HttpContextCacheService>()
            .AsSelf()
            .As <ICacheService>()
            .InstancePerLifetimeScope();

            builder.Register(c => new EntitiesContext(configuration.Current.SqlConnectionString, readOnly: configuration.Current.ReadOnlyMode))
            .AsSelf()
            .As <IEntitiesContext>()
            .As <DbContext>()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <User> >()
            .AsSelf()
            .As <IEntityRepository <User> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <ReservedNamespace> >()
            .AsSelf()
            .As <IEntityRepository <ReservedNamespace> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <CuratedFeed> >()
            .AsSelf()
            .As <IEntityRepository <CuratedFeed> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <CuratedPackage> >()
            .AsSelf()
            .As <IEntityRepository <CuratedPackage> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageRegistration> >()
            .AsSelf()
            .As <IEntityRepository <PackageRegistration> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Package> >()
            .AsSelf()
            .As <IEntityRepository <Package> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDependency> >()
            .AsSelf()
            .As <IEntityRepository <PackageDependency> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDelete> >()
            .AsSelf()
            .As <IEntityRepository <PackageDelete> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <AccountDelete> >()
            .AsSelf()
            .As <IEntityRepository <AccountDelete> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Credential> >()
            .AsSelf()
            .As <IEntityRepository <Credential> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageOwnerRequest> >()
            .AsSelf()
            .As <IEntityRepository <PackageOwnerRequest> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <CuratedFeedService>()
            .AsSelf()
            .As <ICuratedFeedService>()
            .InstancePerLifetimeScope();

            builder.Register(c => new SupportRequestDbContext(configuration.Current.SqlConnectionStringSupportRequest))
            .AsSelf()
            .As <ISupportRequestDbContext>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SupportRequestService>()
            .AsSelf()
            .As <ISupportRequestService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <UserService>()
            .AsSelf()
            .As <IUserService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageNamingConflictValidator>()
            .AsSelf()
            .As <IPackageNamingConflictValidator>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageService>()
            .AsSelf()
            .As <IPackageService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageDeleteService>()
            .AsSelf()
            .As <IPackageDeleteService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <DeleteAccountService>()
            .AsSelf()
            .As <IDeleteAccountService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageOwnerRequestService>()
            .AsSelf()
            .As <IPackageOwnerRequestService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <FormsAuthenticationService>()
            .As <IFormsAuthenticationService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <CookieTempDataProvider>()
            .As <ITempDataProvider>()
            .InstancePerLifetimeScope();

            builder.RegisterType <StatusService>()
            .AsSelf()
            .As <IStatusService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SecurityPolicyService>()
            .AsSelf()
            .As <ISecurityPolicyService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ReservedNamespaceService>()
            .AsSelf()
            .As <IReservedNamespaceService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageUploadService>()
            .AsSelf()
            .As <IPackageUploadService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageOwnershipManagementService>()
            .AsSelf()
            .As <IPackageOwnershipManagementService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ValidationService>()
            .AsSelf()
            .As <IValidationService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ReadMeService>()
            .AsSelf()
            .As <IReadMeService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ApiScopeEvaluator>()
            .AsSelf()
            .As <IApiScopeEvaluator>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SecurePushSubscription>()
            .SingleInstance();

            builder.RegisterType <RequireSecurePushForCoOwnersPolicy>()
            .SingleInstance();

            var mailSenderThunk = new Lazy <IMailSender>(
                () =>
            {
                var settings = configuration;
                if (settings.Current.SmtpUri != null && settings.Current.SmtpUri.IsAbsoluteUri)
                {
                    var smtpUri = new SmtpUri(settings.Current.SmtpUri);

                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        Host           = smtpUri.Host,
                        Port           = smtpUri.Port,
                        EnableSsl      = smtpUri.Secure
                    };

                    if (!string.IsNullOrWhiteSpace(smtpUri.UserName))
                    {
                        mailSenderConfiguration.UseDefaultCredentials = false;
                        mailSenderConfiguration.Credentials           = new NetworkCredential(
                            smtpUri.UserName,
                            smtpUri.Password);
                    }

                    return(new MailSender(mailSenderConfiguration));
                }
                else
                {
                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory,
                        PickupDirectoryLocation = HostingEnvironment.MapPath("~/App_Data/Mail")
                    };

                    return(new MailSender(mailSenderConfiguration));
                }
            });

            builder.Register(c => mailSenderThunk.Value)
            .AsSelf()
            .As <IMailSender>()
            .InstancePerLifetimeScope();

            builder.RegisterType <MessageService>()
            .AsSelf()
            .As <IMessageService>()
            .InstancePerLifetimeScope();

            builder.Register(c => HttpContext.Current.User)
            .AsSelf()
            .As <IPrincipal>()
            .InstancePerLifetimeScope();

            IAuditingService defaultAuditingService = null;

            switch (configuration.Current.StorageType)
            {
            case StorageType.FileSystem:
            case StorageType.NotSpecified:
                ConfigureForLocalFileSystem(builder, configuration);
                defaultAuditingService = GetAuditingServiceForLocalFileSystem(configuration);
                break;

            case StorageType.AzureStorage:
                ConfigureForAzureStorage(builder, configuration, telemetryClient);
                defaultAuditingService = GetAuditingServiceForAzureStorage(builder, configuration);
                break;
            }

            RegisterAsynchronousValidation(builder, configuration);

            RegisterAuditingServices(builder, defaultAuditingService);

            RegisterCookieComplianceService(builder, configuration, diagnosticsService);

            // todo: bind all package curators by convention
            builder.RegisterType <WebMatrixPackageCurator>()
            .AsSelf()
            .As <IAutomaticPackageCurator>()
            .InstancePerLifetimeScope();

            builder.RegisterType <Windows8PackageCurator>()
            .AsSelf()
            .As <IAutomaticPackageCurator>()
            .InstancePerLifetimeScope();

            // todo: bind all commands by convention
            builder.RegisterType <AutomaticallyCuratePackageCommand>()
            .AsSelf()
            .As <IAutomaticallyCuratePackageCommand>()
            .InstancePerLifetimeScope();

            if (configuration.Current.Environment == Constants.DevelopmentEnvironment)
            {
                builder.RegisterType <AllowLocalHttpRedirectPolicy>()
                .As <ISourceDestinationRedirectPolicy>()
                .InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <NoLessSecureDestinationRedirectPolicy>()
                .As <ISourceDestinationRedirectPolicy>()
                .InstancePerLifetimeScope();
            }

            ConfigureAutocomplete(builder, configuration);
        }
        protected override void Load(ContainerBuilder builder)
        {
            var services = new ServiceCollection();

            var configuration       = new ConfigurationService();
            var secretReaderFactory = new SecretReaderFactory(configuration);
            var secretReader        = secretReaderFactory.CreateSecretReader();
            var secretInjector      = secretReaderFactory.CreateSecretInjector(secretReader);

            builder.RegisterInstance(secretInjector)
            .AsSelf()
            .As <ISecretInjector>()
            .SingleInstance();

            configuration.SecretInjector = secretInjector;

            // Register the ILoggerFactory and configure it to use AppInsights if an instrumentation key is provided.
            var instrumentationKey = configuration.Current.AppInsightsInstrumentationKey;

            if (!string.IsNullOrEmpty(instrumentationKey))
            {
                TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
            }

            var loggerConfiguration = LoggingSetup.CreateDefaultLoggerConfiguration(withConsoleLogger: false);
            var loggerFactory       = LoggingSetup.CreateLoggerFactory(loggerConfiguration);

            var telemetryClient = TelemetryClientWrapper.Instance;

            builder.RegisterInstance(telemetryClient)
            .AsSelf()
            .As <ITelemetryClient>()
            .SingleInstance();

            var diagnosticsService = new DiagnosticsService(telemetryClient);

            builder.RegisterInstance(diagnosticsService)
            .AsSelf()
            .As <IDiagnosticsService>()
            .SingleInstance();

            services.AddSingleton(loggerFactory);
            services.AddSingleton(typeof(ILogger <>), typeof(Logger <>));

            UrlHelperExtensions.SetConfigurationService(configuration);

            builder.RegisterInstance(configuration)
            .AsSelf()
            .As <IGalleryConfigurationService>();

            builder.Register(c => configuration.Current)
            .AsSelf()
            .AsImplementedInterfaces();

            // Force the read of this configuration, so it will be initialized on startup
            builder.Register(c => configuration.Features)
            .AsSelf()
            .As <FeatureConfiguration>();

            builder.Register(c => configuration.PackageDelete)
            .As <IPackageDeleteConfiguration>();

            var telemetryService = new TelemetryService(diagnosticsService, telemetryClient);

            builder.RegisterInstance(telemetryService)
            .AsSelf()
            .As <ITelemetryService>()
            .As <IFeatureFlagTelemetryService>()
            .SingleInstance();

            builder.RegisterType <CredentialBuilder>().As <ICredentialBuilder>().SingleInstance();
            builder.RegisterType <CredentialValidator>().As <ICredentialValidator>().SingleInstance();

            builder.RegisterInstance(LuceneCommon.GetDirectory(configuration.Current.LuceneIndexLocation))
            .As <Lucene.Net.Store.Directory>()
            .SingleInstance();

            ConfigureResilientSearch(loggerFactory, configuration, telemetryService, services);
            ConfigureSearch(builder, configuration);

            builder.RegisterType <DateTimeProvider>().AsSelf().As <IDateTimeProvider>().SingleInstance();

            builder.RegisterType <HttpContextCacheService>()
            .AsSelf()
            .As <ICacheService>()
            .InstancePerLifetimeScope();

            var galleryDbConnectionFactory = CreateDbConnectionFactory(
                diagnosticsService,
                nameof(EntitiesContext),
                configuration.Current.SqlConnectionString,
                secretInjector);

            builder.RegisterInstance(galleryDbConnectionFactory)
            .AsSelf()
            .As <ISqlConnectionFactory>()
            .SingleInstance();

            builder.Register(c => new EntitiesContext(CreateDbConnection(galleryDbConnectionFactory), configuration.Current.ReadOnlyMode))
            .AsSelf()
            .As <IEntitiesContext>()
            .As <DbContext>()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <User> >()
            .AsSelf()
            .As <IEntityRepository <User> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <ReservedNamespace> >()
            .AsSelf()
            .As <IEntityRepository <ReservedNamespace> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageRegistration> >()
            .AsSelf()
            .As <IEntityRepository <PackageRegistration> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Package> >()
            .AsSelf()
            .As <IEntityRepository <Package> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDependency> >()
            .AsSelf()
            .As <IEntityRepository <PackageDependency> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDelete> >()
            .AsSelf()
            .As <IEntityRepository <PackageDelete> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Certificate> >()
            .AsSelf()
            .As <IEntityRepository <Certificate> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <AccountDelete> >()
            .AsSelf()
            .As <IEntityRepository <AccountDelete> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Credential> >()
            .AsSelf()
            .As <IEntityRepository <Credential> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Scope> >()
            .AsSelf()
            .As <IEntityRepository <Scope> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageOwnerRequest> >()
            .AsSelf()
            .As <IEntityRepository <PackageOwnerRequest> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Organization> >()
            .AsSelf()
            .As <IEntityRepository <Organization> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <SymbolPackage> >()
            .AsSelf()
            .As <IEntityRepository <SymbolPackage> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <PackageDeprecation> >()
            .AsSelf()
            .As <IEntityRepository <PackageDeprecation> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Cve> >()
            .AsSelf()
            .As <IEntityRepository <Cve> >()
            .InstancePerLifetimeScope();

            builder.RegisterType <EntityRepository <Cwe> >()
            .AsSelf()
            .As <IEntityRepository <Cwe> >()
            .InstancePerLifetimeScope();

            var supportDbConnectionFactory = CreateDbConnectionFactory(
                diagnosticsService,
                nameof(SupportRequestDbContext),
                configuration.Current.SqlConnectionStringSupportRequest,
                secretInjector);

            builder.Register(c => new SupportRequestDbContext(CreateDbConnection(supportDbConnectionFactory)))
            .AsSelf()
            .As <ISupportRequestDbContext>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SupportRequestService>()
            .AsSelf()
            .As <ISupportRequestService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <UserService>()
            .AsSelf()
            .As <IUserService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageService>()
            .AsSelf()
            .As <IPackageService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageDeleteService>()
            .AsSelf()
            .As <IPackageDeleteService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <DeleteAccountService>()
            .AsSelf()
            .As <IDeleteAccountService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageOwnerRequestService>()
            .AsSelf()
            .As <IPackageOwnerRequestService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <FormsAuthenticationService>()
            .As <IFormsAuthenticationService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <CookieTempDataProvider>()
            .As <ITempDataProvider>()
            .InstancePerLifetimeScope();

            builder.RegisterType <StatusService>()
            .AsSelf()
            .As <IStatusService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SecurityPolicyService>()
            .AsSelf()
            .As <ISecurityPolicyService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ReservedNamespaceService>()
            .AsSelf()
            .As <IReservedNamespaceService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SymbolPackageService>()
            .AsSelf()
            .As <ISymbolPackageService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageUploadService>()
            .AsSelf()
            .As <IPackageUploadService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <SymbolPackageUploadService>()
            .AsSelf()
            .As <ISymbolPackageUploadService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageOwnershipManagementService>()
            .AsSelf()
            .As <IPackageOwnershipManagementService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ValidationService>()
            .AsSelf()
            .As <IValidationService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ReadMeService>()
            .AsSelf()
            .As <IReadMeService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ApiScopeEvaluator>()
            .AsSelf()
            .As <IApiScopeEvaluator>()
            .InstancePerLifetimeScope();

            builder.RegisterType <ContentObjectService>()
            .AsSelf()
            .As <IContentObjectService>()
            .SingleInstance();

            builder.RegisterType <CertificateValidator>()
            .AsSelf()
            .As <ICertificateValidator>()
            .SingleInstance();

            builder.RegisterType <CertificateService>()
            .AsSelf()
            .As <ICertificateService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <TyposquattingService>()
            .AsSelf()
            .As <ITyposquattingService>()
            .InstancePerLifetimeScope();

            builder.RegisterType <TyposquattingCheckListCacheService>()
            .AsSelf()
            .As <ITyposquattingCheckListCacheService>()
            .SingleInstance();

            builder.Register <ServiceDiscoveryClient>(c =>
                                                      new ServiceDiscoveryClient(c.Resolve <IAppConfiguration>().ServiceDiscoveryUri))
            .As <IServiceDiscoveryClient>();

            builder.RegisterType <LicenseExpressionSplitter>()
            .As <ILicenseExpressionSplitter>()
            .InstancePerLifetimeScope();

            builder.RegisterType <LicenseExpressionParser>()
            .As <ILicenseExpressionParser>()
            .InstancePerLifetimeScope();

            builder.RegisterType <LicenseExpressionSegmentator>()
            .As <ILicenseExpressionSegmentator>()
            .InstancePerLifetimeScope();

            builder.RegisterType <PackageDeprecationService>()
            .As <IPackageDeprecationService>()
            .InstancePerLifetimeScope();

            RegisterFeatureFlagsService(builder, configuration);
            RegisterMessagingService(builder, configuration);

            builder.Register(c => HttpContext.Current.User)
            .AsSelf()
            .As <IPrincipal>()
            .InstancePerLifetimeScope();

            IAuditingService defaultAuditingService = null;

            switch (configuration.Current.StorageType)
            {
            case StorageType.FileSystem:
            case StorageType.NotSpecified:
                ConfigureForLocalFileSystem(builder, configuration);
                defaultAuditingService = GetAuditingServiceForLocalFileSystem(configuration);
                break;

            case StorageType.AzureStorage:
                ConfigureForAzureStorage(builder, configuration, telemetryClient);
                defaultAuditingService = GetAuditingServiceForAzureStorage(builder, configuration);
                break;
            }

            RegisterAsynchronousValidation(builder, diagnosticsService, configuration, secretInjector);

            RegisterAuditingServices(builder, defaultAuditingService);

            RegisterCookieComplianceService(builder, configuration, diagnosticsService);

            builder.RegisterType <MicrosoftTeamSubscription>()
            .AsSelf()
            .InstancePerLifetimeScope();

            if (configuration.Current.Environment == GalleryConstants.DevelopmentEnvironment)
            {
                builder.RegisterType <AllowLocalHttpRedirectPolicy>()
                .As <ISourceDestinationRedirectPolicy>()
                .InstancePerLifetimeScope();
            }
            else
            {
                builder.RegisterType <NoLessSecureDestinationRedirectPolicy>()
                .As <ISourceDestinationRedirectPolicy>()
                .InstancePerLifetimeScope();
            }

            ConfigureAutocomplete(builder, configuration);
            builder.Populate(services);
        }
Exemple #12
0
        public override void Load()
        {
            var configuration = new ConfigurationService();

            Bind <ConfigurationService>()
            .ToMethod(context => configuration);
            Bind <IAppConfiguration>()
            .ToMethod(context => configuration.Current);
            Bind <PoliteCaptcha.IConfigurationSource>()
            .ToMethod(context => configuration);

            Bind <Lucene.Net.Store.Directory>()
            .ToMethod(_ => LuceneCommon.GetDirectory(configuration.Current.LuceneIndexLocation))
            .InSingletonScope();

            ConfigureSearch(configuration);

            if (!String.IsNullOrEmpty(configuration.Current.AzureStorageConnectionString))
            {
                Bind <ErrorLog>()
                .ToMethod(_ => new TableErrorLog(configuration.Current.AzureStorageConnectionString))
                .InSingletonScope();
            }
            else
            {
                Bind <ErrorLog>()
                .ToMethod(_ => new SqlErrorLog(configuration.Current.SqlConnectionString))
                .InSingletonScope();
            }

            Bind <ICacheService>()
            .To <HttpContextCacheService>()
            .InRequestScope();

            Bind <IContentService>()
            .To <ContentService>()
            .InSingletonScope();

            Bind <IEntitiesContext>()
            .ToMethod(context => new EntitiesContext(configuration.Current.SqlConnectionString, readOnly: configuration.Current.ReadOnlyMode))
            .InRequestScope();

            Bind <IEntityRepository <User> >()
            .To <EntityRepository <User> >()
            .InRequestScope();

            Bind <IEntityRepository <CuratedFeed> >()
            .To <EntityRepository <CuratedFeed> >()
            .InRequestScope();

            Bind <IEntityRepository <CuratedPackage> >()
            .To <EntityRepository <CuratedPackage> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageRegistration> >()
            .To <EntityRepository <PackageRegistration> >()
            .InRequestScope();

            Bind <IEntityRepository <Package> >()
            .To <EntityRepository <Package> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageDependency> >()
            .To <EntityRepository <PackageDependency> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageStatistics> >()
            .To <EntityRepository <PackageStatistics> >()
            .InRequestScope();

            Bind <IEntityRepository <Credential> >()
            .To <EntityRepository <Credential> >()
            .InRequestScope();

            Bind <ICuratedFeedService>()
            .To <CuratedFeedService>()
            .InRequestScope();

            Bind <IUserService>()
            .To <UserService>()
            .InRequestScope();

            Bind <IPackageService>()
            .To <PackageService>()
            .InRequestScope();

            Bind <EditPackageService>().ToSelf();

            Bind <IFormsAuthenticationService>()
            .To <FormsAuthenticationService>()
            .InSingletonScope();

            Bind <IControllerFactory>()
            .To <NuGetControllerFactory>()
            .InRequestScope();

            Bind <INuGetExeDownloaderService>()
            .To <NuGetExeDownloaderService>()
            .InRequestScope();

            Bind <IStatusService>()
            .To <StatusService>()
            .InRequestScope();

            var mailSenderThunk = new Lazy <IMailSender>(
                () =>
            {
                var settings = Kernel.Get <ConfigurationService>();
                if (settings.Current.SmtpUri != null && settings.Current.SmtpUri.IsAbsoluteUri)
                {
                    var smtpUri = new SmtpUri(settings.Current.SmtpUri);

                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        Host           = smtpUri.Host,
                        Port           = smtpUri.Port,
                        EnableSsl      = smtpUri.Secure
                    };

                    if (!String.IsNullOrWhiteSpace(smtpUri.UserName))
                    {
                        mailSenderConfiguration.UseDefaultCredentials = false;
                        mailSenderConfiguration.Credentials           = new NetworkCredential(
                            smtpUri.UserName,
                            smtpUri.Password);
                    }

                    return(new MailSender(mailSenderConfiguration));
                }
                else
                {
                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory,
                        PickupDirectoryLocation = HostingEnvironment.MapPath("~/App_Data/Mail")
                    };

                    return(new MailSender(mailSenderConfiguration));
                }
            });

            Bind <IMailSender>()
            .ToMethod(context => mailSenderThunk.Value);

            Bind <IMessageService>()
            .To <MessageService>();

            Bind <IPrincipal>().ToMethod(context => HttpContext.Current.User);

            switch (configuration.Current.StorageType)
            {
            case StorageType.FileSystem:
            case StorageType.NotSpecified:
                ConfigureForLocalFileSystem();
                break;

            case StorageType.AzureStorage:
                ConfigureForAzureStorage(configuration);
                break;
            }

            Bind <IFileSystemService>()
            .To <FileSystemService>()
            .InSingletonScope();

            Bind <IPackageFileService>()
            .To <PackageFileService>();

            Bind <IEntityRepository <PackageOwnerRequest> >()
            .To <EntityRepository <PackageOwnerRequest> >()
            .InRequestScope();

            Bind <IUploadFileService>()
            .To <UploadFileService>();

            // todo: bind all package curators by convention
            Bind <IAutomaticPackageCurator>()
            .To <WebMatrixPackageCurator>();
            Bind <IAutomaticPackageCurator>()
            .To <Windows8PackageCurator>();

            // todo: bind all commands by convention
            Bind <IAutomaticallyCuratePackageCommand>()
            .To <AutomaticallyCuratePackageCommand>()
            .InRequestScope();

            Bind <IPackageIdsQuery>()
            .To <PackageIdsQuery>()
            .InRequestScope();
            Bind <IPackageVersionsQuery>()
            .To <PackageVersionsQuery>()
            .InRequestScope();
        }
Exemple #13
0
        public override void Load()
        {
            var configuration = new Configuration();

            Bind <IConfiguration>()
            .ToMethod(context => configuration);
            Bind <PoliteCaptcha.IConfigurationSource>()
            .ToMethod(context => Configuration.GetPoliteCaptchaConfiguration());

            Bind <Lucene.Net.Store.Directory>()
            .ToMethod(_ => LuceneCommon.GetDirectory())
            .InSingletonScope();

            Bind <ISearchService>()
            .To <LuceneSearchService>()
            .InRequestScope();

            if (!String.IsNullOrEmpty(configuration.AzureDiagnosticsConnectionString))
            {
                Bind <ErrorLog>()
                .ToMethod(_ => new TableErrorLog(configuration.AzureDiagnosticsConnectionString))
                .InSingletonScope();
            }
            else
            {
                Bind <ErrorLog>()
                .ToMethod(_ => new SqlErrorLog(configuration.SqlConnectionString))
                .InSingletonScope();
            }

            if (IsDeployedToCloud)
            {
                // when running on Windows Azure, use the Azure Cache service if available
                if (!String.IsNullOrEmpty(configuration.AzureCacheEndpoint))
                {
                    Bind <ICacheService>()
                    .To <CloudCacheService>()
                    .InSingletonScope();
                }
                else
                {
                    Bind <ICacheService>()
                    .To <HttpContextCacheService>()
                    .InRequestScope();
                }

                // when running on Windows Azure, pull the statistics from the warehouse via storage
                Bind <IReportService>()
                .ToMethod(context => new CloudReportService(configuration.AzureStatisticsConnectionString))
                .InSingletonScope();

                Bind <IStatisticsService>()
                .To <JsonStatisticsService>()
                .InSingletonScope();
            }
            else
            {
                // when running locally on dev box, use the built-in ASP.NET Http Cache
                Bind <ICacheService>()
                .To <HttpContextCacheService>()
                .InRequestScope();
            }

            Bind <IEntitiesContext>()
            .ToMethod(context => new EntitiesContext(configuration.SqlConnectionString, readOnly: configuration.ReadOnlyMode))
            .InRequestScope();

            Bind <IEntityRepository <User> >()
            .To <EntityRepository <User> >()
            .InRequestScope();

            Bind <IEntityRepository <CuratedFeed> >()
            .To <EntityRepository <CuratedFeed> >()
            .InRequestScope();

            Bind <IEntityRepository <CuratedPackage> >()
            .To <EntityRepository <CuratedPackage> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageRegistration> >()
            .To <EntityRepository <PackageRegistration> >()
            .InRequestScope();

            Bind <IEntityRepository <Package> >()
            .To <EntityRepository <Package> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageAuthor> >()
            .To <EntityRepository <PackageAuthor> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageDependency> >()
            .To <EntityRepository <PackageDependency> >()
            .InRequestScope();

            Bind <IEntityRepository <PackageStatistics> >()
            .To <EntityRepository <PackageStatistics> >()
            .InRequestScope();

            Bind <ICuratedFeedService>()
            .To <CuratedFeedService>()
            .InRequestScope();

            Bind <IUserService>()
            .To <UserService>()
            .InRequestScope();
            //modified by fwang5 2013/5/15
            Bind <ILdapService>()
            .To <LdapService>()
            .InRequestScope();

            Bind <IPackageSource>()
            .To <PackageSource>()
            .InRequestScope();

            Bind <IPackageService>()
            .To <PackageService>()
            .InRequestScope();

            Bind <ICryptographyService>()
            .To <CryptographyService>()
            .InRequestScope();

            Bind <IFormsAuthenticationService>()
            .To <FormsAuthenticationService>()
            .InSingletonScope();

            Bind <IControllerFactory>()
            .To <NuGetControllerFactory>()
            .InRequestScope();

            Bind <IIndexingService>()
            .To <LuceneIndexingService>()
            .InRequestScope();

            Bind <INuGetExeDownloaderService>()
            .To <NuGetExeDownloaderService>()
            .InRequestScope();

            var mailSenderThunk = new Lazy <IMailSender>(
                () =>
            {
                var settings = Kernel.Get <IConfiguration>();
                if (settings.UseSmtp)
                {
                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod = SmtpDeliveryMethod.Network,
                        Host           = settings.SmtpHost,
                        Port           = settings.SmtpPort,
                        //modified by fwang5 2013/5/15
                        EnableSsl = false
                    };

                    if (!String.IsNullOrWhiteSpace(settings.SmtpUsername))
                    {
                        mailSenderConfiguration.UseDefaultCredentials = false;
                        mailSenderConfiguration.Credentials           = new NetworkCredential(
                            settings.SmtpUsername,
                            settings.SmtpPassword);
                    }

                    return(new MailSender(mailSenderConfiguration));
                }
                else
                {
                    var mailSenderConfiguration = new MailSenderConfiguration
                    {
                        DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory,
                        PickupDirectoryLocation = HostingEnvironment.MapPath("~/App_Data/Mail")
                    };

                    return(new MailSender(mailSenderConfiguration));
                }
            });

            Bind <IMailSender>()
            .ToMethod(context => mailSenderThunk.Value);

            Bind <IMessageService>()
            .To <MessageService>();

            Bind <IPrincipal>().ToMethod(context => HttpContext.Current.User);

            switch (configuration.PackageStoreType)
            {
            case PackageStoreType.FileSystem:
            case PackageStoreType.NotSpecified:
                Bind <IFileStorageService>()
                .To <FileSystemFileStorageService>()
                .InSingletonScope();
                break;

            case PackageStoreType.AzureStorageBlob:
                Bind <ICloudBlobClient>()
                .ToMethod(
                    _ => new CloudBlobClientWrapper(configuration.AzureStorageConnectionString))
                .InSingletonScope();
                Bind <IFileStorageService>()
                .To <CloudBlobFileStorageService>()
                .InSingletonScope();
                break;
            }

            Bind <IFileSystemService>()
            .To <FileSystemService>()
            .InSingletonScope();

            Bind <IPackageFileService>()
            .To <PackageFileService>();

            Bind <IEntityRepository <PackageOwnerRequest> >()
            .To <EntityRepository <PackageOwnerRequest> >()
            .InRequestScope();

            Bind <IUploadFileService>()
            .To <UploadFileService>();

            // todo: bind all package curators by convention
            Bind <IAutomaticPackageCurator>()
            .To <WebMatrixPackageCurator>();
            Bind <IAutomaticPackageCurator>()
            .To <Windows8PackageCurator>();

            // todo: bind all commands by convention
            Bind <IAutomaticallyCuratePackageCommand>()
            .To <AutomaticallyCuratePackageCommand>()
            .InRequestScope();
            Bind <ICreateCuratedPackageCommand>()
            .To <CreateCuratedPackageCommand>()
            .InRequestScope();
            Bind <IDeleteCuratedPackageCommand>()
            .To <DeleteCuratedPackageCommand>()
            .InRequestScope();
            Bind <IModifyCuratedPackageCommand>()
            .To <ModifyCuratedPackageCommand>()
            .InRequestScope();

            // todo: bind all queries by convention
            Bind <ICuratedFeedByKeyQuery>()
            .To <CuratedFeedByKeyQuery>()
            .InRequestScope();
            Bind <ICuratedFeedByNameQuery>()
            .To <CuratedFeedByNameQuery>()
            .InRequestScope();
            Bind <ICuratedFeedsByManagerQuery>()
            .To <CuratedFeedsByManagerQuery>()
            .InRequestScope();
            Bind <IPackageRegistrationByKeyQuery>()
            .To <PackageRegistrationByKeyQuery>()
            .InRequestScope();
            Bind <IPackageRegistrationByIdQuery>()
            .To <PackageRegistrationByIdQuery>()
            .InRequestScope();

            Bind <IAggregateStatsService>()
            .To <AggregateStatsService>()
            .InRequestScope();
            Bind <IPackageIdsQuery>()
            .To <PackageIdsQuery>()
            .InRequestScope();
            Bind <IPackageVersionsQuery>()
            .To <PackageVersionsQuery>()
            .InRequestScope();
        }