正在添加Microsoft.蔚蓝色的WebJobs.扩展.Azure Function项目的SignalRService



我目前正在开发一个WebApp,其中我有一个Azure Function API后端,可以与Azure Cosmos数据库对话。我已经将依赖注入添加到我的项目中,如本文所述:https://learn.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection

我的启动类如下:

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PoolScoreTrackerV2.API.Config;
using PoolScoreTrackerV2.Functions.Services;
using System;
[assembly: FunctionsStartup(typeof(PoolScoreTrackerV2.Functions.Startup))]
namespace PoolScoreTrackerV2.Functions
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddLogging(loggingBuilder =>
{
loggingBuilder.AddFilter(level => true);
});
builder.Services.AddOptions<CosmosDbOptions>()
.Configure<IConfiguration>((settings, configuration) =>
{
configuration.GetSection("CosmosDb").Bind(settings);
});
builder.Services.AddSingleton<ICosmosDbService>(
new CosmosDbService(
new CosmosClient(
Environment.GetEnvironmentVariable("CosmosDb:CosmosDbConnection")
)
)
);
}
}
}

这里有一个我如何在函数中使用它的例子:

namespace PoolScoreTrackerV2.API.Functions.Matches
{
public class GetMatches
{
private readonly ICosmosDbService _cosmosDbService;
private readonly ILogger<GetMatches> _logger;
private readonly CosmosDbOptions _settings;
public GetMatches(ICosmosDbService cosmosDbService, ILogger<GetMatches> logger, IOptions<CosmosDbOptions> settings)
{
_cosmosDbService = cosmosDbService;
_logger = logger;
_settings = settings.Value;
_cosmosDbService.InitializeCollection(_settings.DatabaseId, _settings.ContainerId);
}
[FunctionName("GetMatches")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "matches")] HttpRequest req, ClaimsPrincipal principal)
{
if (ValidationExtensions.AuthorizeUser(principal) == false)
{
return new UnauthorizedResult();
}
var data = await _cosmosDbService.GetAsync<Match>("SELECT * FROM m where m.type = 'match'");
_logger.LogInformation("GET Matches");
return new OkObjectResult(data);
}
}
}

一切都按预期进行,直到我需要为一个需要实时数据的特定页面添加SignalR。在刚刚安装SignalR软件包Microsoft之后。蔚蓝色的WebJobs。扩展。SignalRService,我在控制台中注意到这个错误:

[2020-10-14T07:05:00.381] Unsupported service transport type: . Use default Transient instead.

当我尝试访问API端点时,我在所有端点上都得到500个错误,控制台中出现以下错误:

Executed 'GetMatches' (Failed, Id=3a10737c-7abe-4e18-aeb6-1d442b36ef7a, Duration=43ms)
[2020-10-14T07:05:08.289] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'PoolScoreTrackerV2.Functions.Services.ICosmosDbService' while attempting to activate 'PoolScoreTrackerV2.API.Functions.Matches.GetMatches'.

我已将所有软件包更新到最新版本,并尝试重新安装所有软件包,但仍然出现相同的错误。当我删除SignalR包时,所有的错误都会消失。我已经测试过多次了。

将版本更改为1.0.2删除了依赖注入错误。我仍然收到不支持的服务传输类型警告,但我现在可以毫无例外地查询数据。

最新更新