
HttpClient & Networking
HttpClient, HttpClientFactory, request/response, error handling, retry policies, async patterns
1Why use IHttpClientFactory instead of instantiating HttpClient directly?
Why use IHttpClientFactory instead of instantiating HttpClient directly?
Risposta
IHttpClientFactory automatically manages the lifecycle of HttpClient instances and prevents socket exhaustion. Directly instantiating HttpClient in a using statement can cause TIME_WAIT connection issues that remain open even after disposal. Using IHttpClientFactory also enables configuring resilience policies with Polly and efficiently managing connection pooling.
2What is the main difference between a Named Client and a Typed Client?
What is the main difference between a Named Client and a Typed Client?
Risposta
A Typed Client encapsulates HTTP call logic in a dedicated class with dependency injection, while a Named Client is retrieved via IHttpClientFactory.CreateClient(name). Typed Clients offer better separation of concerns and facilitate unit testing by encapsulating configuration and business logic. Named Clients are useful for simple cases where multiple different configurations are needed without complex business logic.
3How to configure a global timeout for all HttpClient instances in an application?
How to configure a global timeout for all HttpClient instances in an application?
Risposta
Configuring the timeout via ConfigurePrimaryHttpMessageHandler allows defining a timeout at the handler level that will apply to all clients created by the factory. This approach centralizes configuration and avoids code repetition. It's also possible to configure the timeout individually on each HttpClient, but this becomes difficult to maintain in a large application with multiple configured clients.
Which method allows reading the body of an HTTP response as a string?
What is the role of a DelegatingHandler in the HttpClient pipeline?
+17 domande da colloquio
Altri argomenti di colloquio .NET
C# Basics
LINQ & Delegates
C# Language Essentials
ASP.NET Core Fundamentals
ASP.NET Core Request Lifecycle
Configuration & Settings
Application Lifecycle
Dependency Injection
Entity Framework Core
Minimal APIs
Web API Development
Async in ASP.NET Core
Authentication & Authorization
JSON Serialization
Entity Framework Core Advanced
C# Advanced Features
Clean Architecture
Logging, Monitoring & Observability
Unit Testing & xUnit
Integration Testing
Docker & Containerization
NuGet Package Management
Memory Management & GC
Reactive Programming
Async/await & Patterns
.NET Design Patterns
Performance Optimization
Security & Best Practices
SignalR & Real-time
Microservices Architecture
Padroneggia .NET per il tuo prossimo colloquio
Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.
Inizia gratis