You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public interface IPetStoreClient
{
[Post("/store/order")]
Task<Order> PlaceOrder([Body] Order body);
[Get("/store/order/{orderId}")]
Task<Order> GetOrderById(long orderId);
[Delete("/store/order/{orderId}")]
Task DeleteOrder(long orderId);
}
Exception
An unhandled exception of type 'System.AggregateException' occurred in Microsoft.Extensions.DependencyInjection.dll: 'Some services are not able to be constructed'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.InvalidOperationException : Unable to resolve service for type 'Refit.IRequestBuilder' while attempting to activate 'Refit.Implementation.Generated+BLLExternalClientsIPetStoreClient'.
Injection
builder.Services
.AddRefitClient<IPetStoreClient>()
.ConfigureHttpClient(c => c.BaseAddress = new Uri(config.PetStoreClientSettings.BaseUrl));
Usage
public class HelperController : Controller
{
private readonly IPetStoreClient _petStoreClient;
public HelperController(IPetStoreClient petStoreClient)
{
_petStoreClient = petStoreClient;
}
[HttpGet("test")]
public async Task<IActionResult> Get()
{
var response = await _petStoreClient.GetOrderById(24);
return Ok(response);
}
}
Note 1
Same error when creating inside constructor
public class TestController : Controller
{
private readonly IPetStoreClient _petStoreClient;
public HelperController(ConfigSettings configSettings)
{
_petStoreClient = RestService.For<IPetStoreClient>(configSettings.PetStoreClientSettings.BaseUrl);
}
Note 2
Same error when creating instance
[HttpGet("test")]
public async Task<IActionResult> Get()
{
var client = RestService.For<IPetStoreClient>(_configSettings.PetStoreClientSettings.BaseUrl);
var response = await client.GetOrderById(24);
return Ok(response);
}
Refit.IRequestBuilder dependency injection exception 🐞
Interface
Exception
An unhandled exception of type 'System.AggregateException' occurred in Microsoft.Extensions.DependencyInjection.dll: 'Some services are not able to be constructed'
Inner exceptions found, see $exception in variables window for more details.
Innermost exception System.InvalidOperationException : Unable to resolve service for type 'Refit.IRequestBuilder' while attempting to activate 'Refit.Implementation.Generated+BLLExternalClientsIPetStoreClient'.
Injection
Usage
Note 1
Same error when creating inside constructor
Note 2
Same error when creating instance
Step to reproduce
Refit.HttpClientFactory v7.0.0
Refit v7.0.0
Reproduction repository
https://github.com/reactiveui/refit
Expected behavior
Dependency injection IRequestBuilder exception
Screenshots 🖼️
No response
IDE
Visual Studio 2022, Rider Windows, Visual Studio Code
Operating system
Windows
Version
No response
Device
No response
Refit Version
7.0.0
Additional information ℹ️
null
The text was updated successfully, but these errors were encountered: