InvalidOperationException当我调用GET服务时

时间:2019-06-23 09:30:43

标签: c# asp.net-core

我收到“ InvalidOperationException:当我调用GET服务时,我正在获取此错误。“ GetDownloadOptionsAsync”方法运行良好。我只需要如何在API中调用该方法即可。谢谢。

  

InvalidOperationException:尝试激活“ GetUrlService.Controllers.ValuesController”时,无法解析类型为“ YoutubeDownloader.Services.DownloadService”的服务。           Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp,Type type,Type requiredBy,bool isDefaultParameterRequired)           lambda_method(Closure,IServiceProvider,object [])           Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider + <> c__DisplayClass4_0.b__0(ControllerContext controllerContext)           Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider + <> c__DisplayClass5_0.g__CreateController | 0(ControllerContext controllerContext)           Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(下一个参考状态,参考作用域范围,参考对象状态,参考布尔已完成)           Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()           Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()

public class DownloadService
{
    private readonly SettingsService _settingsService;
    private readonly IYoutubeClient _youtubeClient = new YoutubeClient();
    private readonly IYoutubeConverter _youtubeConverter = new YoutubeConverter();        
    private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
    private int _concurrentDownloadCount;

    public DownloadService(SettingsService settingsService)
    {
        _settingsService = settingsService;

        // Increase maximum concurrent connections
        ServicePointManager.DefaultConnectionLimit = 20;
    }

    public async Task<IReadOnlyList<DownloadOption>> GetDownloadOptionsAsync(string videoId)
    {
        var result = new List<DownloadOption>();

        //some code here
        return result;
    }
}        

[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
    private readonly DownloadService _downloadService;

    public ValuesController(DownloadService downloadService)
    {
       _downloadService = downloadService;
    }

    // GET api/values/5
    [HttpGet("{vidID}")]
    public async Task<ActionResult<string>> GetAsync(string vidID) 
    {
        var vidURL = "";    
        var downloadOptions = await _downloadService.GetDownloadOptionsAsync(vidID);

        return null;
    }
}

0 个答案:

没有答案