Overview
Microsoft.PackageManagement.Search.Web is a small, focused shared library that provides the reusable ASP.NET Core infrastructure for NuGet search service web applications. It contains no controllers, no business logic, and no Azure Search integration of its own. Instead, it supplies three pieces of infrastructure:
- Host construction — a pre-configured
IHostBuilderthat strips out noisy environment variables and wires in Autofac as the DI container. - Startup helpers — Azure Key Vault secret injection into configuration, standard ASP.NET Core middleware pipeline setup (routing, CORS, HSTS, security headers), and a utility for building Application Insights operation names.
- Exception filtering — an MVC
ExceptionFilterAttributethat maps domain exceptions fromNuGet.Services.AzureSearchto appropriate HTTP status codes.
net6.0 and is published as a versioned NuGet package alongside the rest of the NuGetGallery jobs packages.
Role in the System
Consumed by SearchService.Core
NuGet.Services.SearchService.Core is the primary consumer. Its Program.cs calls HostBuilderHelper.CreateHostBuilder and its Startup.cs calls StartupHelper methods.Sits above AzureSearch
Depends on
NuGet.Services.AzureSearch for AzureSearchException, InvalidSearchRequestException, and ErrorResponse types used in the exception filter.Enables multi-host deployment
By encapsulating host bootstrap logic in a shared library, additional search-flavored web applications can reuse the same secure configuration and middleware setup without duplicating Key Vault wiring.
Security boundary
All incoming environment variables are filtered to only the
APPSETTING_ prefix. Key Vault secrets are injected at startup; foreground request threads are forbidden from triggering uncached secret reads to avoid deadlocks.Key Files and Classes
| File | Class | Purpose |
|---|---|---|
HostBuilderHelper.cs | HostBuilderHelper | Static factory that creates the IHostBuilder. Removes all default EnvironmentVariablesConfigurationSource entries and replaces them with a single source scoped to the APPSETTING_ prefix. Registers Autofac as the service provider factory. |
StartupHelper.cs | StartupHelper | Static helpers called from a host’s Startup class. Provides GetSecretInjectedConfiguration (Key Vault injection + refresh), Configure (middleware pipeline), and GetOperationName<T> (Application Insights telemetry naming). |
StartupHelper.cs | RefreshableConfiguration | Plain data holder pairing an IRefreshableSecretReaderFactory with the fully injected IConfigurationRoot. |
Support/ApiExceptionFilterAttribute.cs | ApiExceptionFilterAttribute | MVC ExceptionFilterAttribute. Maps AzureSearchException → HTTP 503 and InvalidSearchRequestException → HTTP 400. All other exceptions propagate normally. |
Dependencies
NuGet Package References
| Package | Role |
|---|---|
Microsoft.ApplicationInsights.AspNetCore | Application Insights telemetry integration |
Microsoft.AspNetCore.Http | Lifted transitive dependency — pinned for Component Governance compliance |
System.Drawing.Common | Lifted transitive dependency — pinned for Component Governance compliance |
Framework Reference
| Reference | Notes |
|---|---|
Microsoft.AspNetCore.App | Full ASP.NET Core framework reference; brings in MVC, routing, CORS, HSTS, and hosting APIs |
Internal Project References
| Project | Purpose |
|---|---|
NuGet.Services.AzureSearch | Provides AzureSearchException, InvalidSearchRequestException, and ErrorResponse consumed by the exception filter |
Startup Flow
Notable Patterns and Implementation Details
Environment variable filtering is intentional.
HostBuilderHelper removes all default EnvironmentVariablesConfigurationSource registrations and replaces them with a single source scoped to the APPSETTING_ prefix. This matches the Azure App Service configuration convention and avoids accidentally ingesting hundreds of system-level variables.CORS is caller-controlled.
StartupHelper.Configure accepts an optional Action<CorsPolicyBuilder> parameter. If null, no CORS middleware is added at all. The consuming host passes an open-origin policy — this keeps the CORS policy out of the shared library.Target framework mismatch. This library targets
net6.0 while its primary consumer NuGet.Services.SearchService.Core targets net8.0. The library runs fine under the .NET forward-compatibility model, but has not been updated to match the host’s TFM.