protected override void Load(ContainerBuilder builder) { var diagnosticsService = new DiagnosticsService(); builder.RegisterInstance(diagnosticsService) .AsSelf() .As<IDiagnosticsService>() .SingleInstance(); var configuration = new ConfigurationService(new SecretReaderFactory(diagnosticsService)); 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.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); 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<DateTimeProvider>().AsSelf().As<IDateTimeProvider>().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<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.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<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, configuration); 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); }