6.10IObjectContentConverterFactory Object Content Converter Factory

Created on Aug 17, 2026~2 min read

When the IHttpContentConverterFactory content converter factory cannot find a matching IHttpContentConverter content processor, the system falls back to using the IObjectContentConverterFactory object content converter factory for conversion, which internally performs conversion by returning an ObjectContentConverter() instance. This factory service is configured as a singleton to ensure its uniqueness and stability throughout the application lifecycle.

The following example combines the IObjectContentConverterFactory content converter factory with HttpClient, showing how to easily convert an HttpResponseMessage object into a target type instance through its Read method.

cs
public class YourService(IObjectContentConverterFactory objectContentConverterFactory)  // .NET8+ supports primary constructor injection{    public async Task<string> GetStringAsync()    {        var httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, "https://furion.net/getuser/100");        using var httpClient = new HttpClient();        var httpResponseMessage = await httpClient.SendAsync(httpRequestMessage);        // Call the GetConverter<TResult>(new HttpContentConverterContext(httpResponseMessage)) method to obtain an object content converter instance        // Then call the Read method to convert the HttpResponseMessage object into a target type instance        var context = new HttpContentConverterContext(httpResponseMessage);        return await objectContentConverterFactory.GetConverter<string>(context).ReadAsync<string>(context);    }}