在AWS Lambda上针对“ Microsoft.Extensions.DependencyInjection.IServiceProviderFactory”的依赖关系注册

时间:2018-12-24 07:40:11

标签: c# lambda dependency-injection registration

在ASP.NET Core Lambda Serverless代理应用程序上,已在管道中集成了autofac,在通过localentry点运行时,它可以很好地运行,但是一旦将其部署到AWS lambda上,我将收到以下错误,尽管我已经进行了明确注册

Lambda测试功能引发的错误是

  

Mon Dec 24 06:42:42 UTC 2018:由于客户函数错误,Lambda执行失败,状态为200:调用类型为'API.LambdaEntryPoint'的构造函数时,引发了异常。   检查内部异常以获取更多详细信息。Lambda请求ID:1c86cf63-0747-11e9-b3dc-fd7a21520e5f   UTC 2018年12月24日星期一06:42:42:方法完成,状态为:502

我可能缺少一些小东西。

我已经明确注册了该组件,但是没有帮助。

    public void ConfigureContainer(ContainerBuilder builder)
    {

        builder.RegisterType<AutofacServiceProviderFactory>().As<IServiceProviderFactory<ContainerBuilder>>();

        DependencyContainer.Initialize(builder);
    }



[Injectable]
public class LambdaEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction
{

    public LambdaEntryPoint() : base(AspNetCoreStartupMode.Constructor)
    {

    }
    /// <summary>
    /// The builder has configuration, logging and Amazon API Gateway already configured. The startup class
    /// needs to be configured in this method using the UseStartup<>() method.
    /// </summary>
    /// <param name="builder"></param>
    protected override void Init(IWebHostBuilder builder)
    {
        builder
            .UseStartup<Startup>();
    }

    public override Task<APIGatewayProxyResponse> FunctionHandlerAsync(APIGatewayProxyRequest request, ILambdaContext lambdaContext)
    {
        //lambdaContext
        //request.
        Console.WriteLine("Function handler" + request.Path);

        return base.FunctionHandlerAsync(request, lambdaContext);
    }
}

当它在本地运行时,我应该能够初始化LambdaEntryPoint函数。 (如上所示)

0 个答案:

没有答案