6.14IHttpRemoteService Service

Created on Aug 17, 2026~4 min read

IHttpRemoteService is an entry-point service for sending HTTP remote requests, and it forms the core of the HTTP remote request module. In short, when you need to send an HTTP remote request, you should use the injected IHttpRemoteService service. This service is registered as a singleton by default, so it can be safely used in services of any lifetime.

Before using the IHttpRemoteService service, you need to register and configure the HttpRemote service in the Startup.cs or Program.cs file.

cs
// Register in Startup.cs:services.AddHttpRemote();// In Program.cs, register as follows:// builder.Services.AddHttpRemote();

Then, inject the IHttpRemoteService service in your service, controller, or any class that supports dependency injection.

cs
public class YourService{    private readonly IHttpRemoteService _httpRemoteService;    public YourService(IHttpRemoteService httpRemoteService)    {        _httpRemoteService = httpRemoteService;    }}

If you are using .NET 8 or later, you can simplify the code by injecting via primary constructor:

cs
public class YourService(IHttpRemoteService httpRemoteService){    // Use the httpRemoteService variable}

Alternatively, you can inject it on demand within a specific method:

cs
public class YourService{    public Task<string> GetResource([FromServices] IHttpRemoteService httpRemoteService)    {        // Your code logic    }}