Azure函数依赖注入再次失败

问题描述 投票:0回答:1

我有一个在Azure中运行的Azure V2应用程序。在各种发行版中,这大约是第三次了,我的自定义依赖项注入再次失败了!

这一次比以往任何时候都糟,因为仅当将问题部署到Azure且日志记录是噩梦才能查明正在发生的情况时才会发生。

Azure Functions当前正在按以下方式运行,但出现通常的错误,即无法索引我的Function。

018-11-10T10:41:56.091 [Information] Host Status: {
  "id": "ad-api-dev",
  "state": "Default",
  "version": "2.0.12165.0",
  "versionDetails": "2.0.12165.0 Commit hash: f9d6c271296eaae48f933c67d1df796fd4ff2a94"
}
2018-11-10T10:41:57.607 [Information] Initializing Host.
2018-11-10T10:41:57.607 [Information] Host initialization: ConsecutiveErrors=0, StartupCount=1
2018-11-10T10:41:57.644 [Information] Starting JobHost
2018-11-10T10:41:57.655 [Information] Starting Host (HostId=ad-api-dev, InstanceId=387865be-cfdf-45ca-98ba-2e0091827461, Version=2.0.12165.0, ProcessId=5140, AppDomainId=1, InDebugMode=True, InDiagnosticMode=False, FunctionsExtensionVersion=~2)
2018-11-10T10:41:57.674 [Information] Loading functions metadata
2018-11-10T10:41:57.723 [Information] 15 functions loaded
2018-11-10T10:41:58.158 [Information] Generating 15 job function(s)
2018-11-10T10:41:58.237 [Error] Error indexing method 'CompleteSimulation.Run'
Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException : Error indexing method 'CompleteSimulation.Run' ---> System.InvalidOperationException : Cannot bind parameter 'executionService' to type IExecutionService. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
   at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsyncCore(MethodInfo method,IFunctionIndexCollector index,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 277
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method,IFunctionIndexCollector index,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 167 
   End of inner exception
   at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexMethodAsync(MethodInfo method,IFunctionIndexCollector index,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 175
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at async Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.IndexTypeAsync(Type type,IFunctionIndexCollector index,CancellationToken cancellationToken) at C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs : 103
2018-11-10T10:41:58.574 [Warning] Function 'CompleteSimulation.Run' failed indexing and will be disabled.

我的本地版本可以正常运行,如下所示

Azure Functions Core Tools (2.2.32 Commit hash: c5476ae629a0a438d6850e58eae1f5203c896cd6)
Function Runtime Version: 2.0.12165.0
[10/11/2018 13:35:15] Building host: startup suppressed:False, configuration suppressed: False
[10/11/2018 13:35:15] Reading host configuration file 'Y:\src\modo.solutions\Modo.Esg.Api\ModoSol.Functions.Api\bin\Debug\netstandard2.0\host.json'
[10/11/2018 13:35:15] Host configuration file read:
[10/11/2018 13:35:15] {
[10/11/2018 13:35:15]   "version": "2.0"
[10/11/2018 13:35:15] }
[10/11/2018 13:35:17] Initializing extension with the following settings: Initializing extension with the following settings:

[您可以看到我在本地使用与Azure相同的运行时版本,因此,如果有人知道为什么我的依赖注入将在本地运行,但在部署时不行,将不胜感激。

我正在使用Autofac 4.8.1作为我的依赖项注入容器。

提前感谢。

BTW如果其他任何人都无法解决其功能主机为何无法启动的问题,请遵循以下说明。

  • 进入门户以使用Azure功能并找到并启用实时日志流。
  • 虽然此窗口处于打开状态,但重新部署/发布您的应用程序。
  • 完成后,进入云资源管理器(仅Visual Studio Windows:/)并找到日志。

如果您在部署时没有打开实时日志流窗口,则不会收到任何日志!!

下面的屏幕截图。

enter image description here

dependency-injection azure-functions autofac azure-functions-runtime azure-functions-core-tools
1个回答
0
投票

我已经创建了一种在Azure Functions v3项目中使用Autofac DI的新方法,而无需使用静态函数或注入属性。使用适当的范围调用服务的处置。

GitHub:https://github.com/junalmeida/autofac-azurefunctionsNuGet:https://www.nuget.org/packages/Autofac.Extensions.DependencyInjection.AzureFunctions

随时为我做贡献!

示例

public class Function1 
{
    private readonly IService1 _service1;

    public Function1(IService1 service1)
    {
        _service1 = service1;
    }

    [FunctionName(nameof(Function1))]
    public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")]string myQueueItem, ILogger log)
    {
        ...
    }
© www.soinside.com 2019 - 2024. All rights reserved.