What are .NET Platform Extensions on docs.microsoft.com?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
.NET Platform Extensions are a set of NuGet packages built on top of the .NET runtime that provide cross-cutting functionality not included in the base class libraries. They cover dependency injection, configuration, logging, hosting, HTTP client management, caching, and more. These packages follow the Microsoft.Extensions.* naming convention and are the foundation of ASP.NET Core's infrastructure, but they can be used in any .NET application — console apps, worker services, WPF, MAUI, and libraries. They are documented under the ".NET Platform Extensions" section on docs.microsoft.com.
Core Packages Overview
Dependency Injection
The DI container is the backbone of .NET Platform Extensions. Most other extensions (logging, configuration, HTTP clients) integrate with it through IServiceCollection extension methods.
Configuration
Configuration sources are layered — later sources override earlier ones. Environment variables override JSON files, and command-line arguments override everything.
Logging
The logging abstraction supports structured logging with message templates (not string interpolation). Log providers (Console, Debug, Serilog, NLog, Application Insights) plug in without changing application code.
Hosting and Background Services
Host.CreateDefaultBuilder wires up configuration, logging, and DI automatically. BackgroundService provides a base class for long-running background tasks with graceful shutdown support.
HTTP Client Factory
IHttpClientFactory manages HttpClient lifetimes, preventing socket exhaustion from creating too many clients and DNS stale-cache issues from reusing a single client too long.
Common Pitfalls
- Resolving scoped services from the root provider: Resolving a scoped service (like
DbContext) from the rootIServiceProviderinstead of a scope creates a singleton instance that is never disposed, causing memory leaks and stale data. Always resolve scoped services within ausing var scope = provider.CreateScope(). - Capturing
IServiceProviderin singletons: A singleton service that holds a reference toIServiceProviderand resolves scoped or transient services creates a "captive dependency" — scoped services become effectively singletons. UseIServiceScopeFactoryinstead. - Using string interpolation in log messages:
logger.LogInformation($"Order {orderId}")creates a new string on every call, even when the log level is disabled. Use message templates:logger.LogInformation("Order {OrderId}", orderId)— the template is only formatted when the message is actually logged. - Not using
IOptions<T>for configuration binding: Reading configuration values directly withconfig["Key"]throughout the codebase scatters magic strings everywhere. Use the Options pattern (IOptions<T>,IOptionsMonitor<T>) to bind configuration sections to strongly-typed classes and inject them via DI. - Creating
HttpClientmanually instead of usingIHttpClientFactory:new HttpClient()in ausingblock causes socket exhaustion under load because sockets linger inTIME_WAITstate.IHttpClientFactorymanages handler lifetimes and connection pooling automatically.
Summary
- .NET Platform Extensions are
Microsoft.Extensions.*NuGet packages providing DI, configuration, logging, hosting, and HTTP client management - They are the foundation of ASP.NET Core but work in any .NET application type
- Use
IServiceCollectionto register services andIServiceProviderto resolve them - Configuration supports multiple layered sources (JSON, environment variables, command line)
- Logging uses structured message templates — not string interpolation
IHttpClientFactorymanages HTTP client lifetimes to prevent socket exhaustion
Related reading
- What Are Some Good .NET Profilers?
- What are the benefits of resource.resx files?
- What are the benefits of using C vs F or F vs C?
- What are the best practices for using Assembly Attributes?
- What are the correct version numbers for C?
- What are the differences between ConcurrentQueue and BlockingCollection in .Net?
- What are the differences between Generics in C and Java... and Templates in C?
- What are the differences between the XmlSerializer and BinaryFormatter

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.