我目前正在创建Azure Fucntion。 DI Layer是一个.net标准项目。 我使用autofac作为我的DI库。所有内容都会编译,但在运行时它会为我提供方法未找到异常。我读了很多文章说我需要升级我的所有nuget包。这对我有点帮助。 这是失败的代码
(。netstandard)DI项目 - > InjectConfuguration.cs
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Awesomeness.AutofacInjection;
using Microsoft.Azure.WebJobs.Host.Bindings;
using Microsoft.Azure.WebJobs.Host.Protocols;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Threading.Tasks;
......这里有些代码..
var services = new ServiceCollection();
... some code here ...
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterModule(new ApplicationModule());
containerBuilder.Populate(services); // Exception here
var applicationContainer = containerBuilder.Build();
var serviceProvider = new AutofacServiceProvider(applicationContainer);
return serviceProvider;
例外:
Method not found: 'Void
Autofac.Extensions.DependencyInjection.AutofacRegistration.Populate(Autofac.ContainerBuilder,
System.Collections.Generic.IEnumerable`1<Microsoft.Extensions.DependencyInjection.ServiceDescriptor>)'.
栈跟踪
at ProjectName.Functions.DI.DIConfig.<>c.<.ctor>b__0_0(ContainerBuilder builder)
at AzureFunctions.Autofac.Configuration.DependencyInjection.Initialize(Action`1 cfg)
at ProjectName.Functions.DI.DIConfig..ctor()
(.net framework)功能项目 - &gt; Function1.cs
using System;
using Awesomeness;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace FunctionApp2
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run([TimerTrigger("0 */1 * * * *", RunOnStartup = true)]TimerInfo myTimer, TraceWriter log, [Inject] IAwesomeClass awesomclass)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
log.Info($"{awesomclass.VeryAwesomeMethod()} at: {DateTime.Now}");
}
}
}
我创建了一个复制我的错误的虚拟项目。 https://www.mediafire.com/file/j03x3v6c55gy1aq/Awesomeness.zip
答案 0 :(得分:0)
将 Microsoft.Extensions.DependencyInjection
降级到 ver. 3.1.4
对我来说是有效的。