Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to add Autofac to LambdaEntryPoint in net core 3.0? #616

Closed
Xocix opened this issue Apr 6, 2020 · 7 comments
Closed

Question: How to add Autofac to LambdaEntryPoint in net core 3.0? #616

Xocix opened this issue Apr 6, 2020 · 7 comments
Labels
bug This issue is a bug. module/lambda-client-lib response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.

Comments

@Xocix
Copy link

Xocix commented Apr 6, 2020

Hi,

I am testing out an api project with Amazon.Lambda.AspNetCoreServer and i stumbled upon a problem which i am not sure how to proceed with.
Autofac has changed how its added:
New way: With IHostBuilder .UseServiceProviderFactory(new AutofacServiceProviderFactory()
Old Way: With IWebHostBuilder serviceCollection.AddAutofac()
Also from my understanding IWebHostBuilder will be deprecated which LambdaEntryPoint is using in the Init method.

For the IWebHostBuilder when i try to add Autofac i get this info message from the method:

ONLY FOR PRE-ASP.NET 3.0 HOSTING. THIS WON'T WORK FOR ASP.NET CORE 3.0+ OR GENERIC HOSTING.

And i cant use IHostBuilder with LambdaEntryPoint.

Anyone has done this or has any ideas how to proceed? Thanks in advance!

@cueball6118
Copy link

cueball6118 commented Apr 15, 2020

I am also having issues (.NET Core 3.1) with this and do not have the option of replacing Lambda as the DI provider. My LocalEntryPoint class is simple and shown below, however this seems impossible to wire up in the LambdaEntryPoint class.

public static void Main(string[] args) 
{ 
	CreateHostBuilder(args).Build().Run(); 
}

public static IHostBuilder CreateHostBuilder(string[] args) 
{ 
	return Host.CreateDefaultBuilder(args) 
		.UseServiceProviderFactory(new AutofacServiceProviderFactory()) 
                .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseStartup<Startup>(); }); 
}

normj edited formatting of code to make readable.

@normj
Copy link
Member

normj commented Apr 15, 2020

Yeah I see now the continual use if IWebHostBuilder is a blocker for using Autofac in .NET Core 3.1. Sorry I should have switched to IHostBuilder as part of the major version change that went out with .NET Core 3.1. I was trying to avoid complexity with this library also supporting .NET Core 2.1 which does use IWebHostBuilder.

I don't want to make significant set breaking changes just a couple weeks after the last major version came out so let me think if there is a less invasive approach to unblock you all.

@normj
Copy link
Member

normj commented Apr 18, 2020

I have created PR #633 to switch to IHostBuilder unless the function overrode the CreateWebHostBuilder function.

@normj
Copy link
Member

normj commented Apr 28, 2020

Version 5.1.0 of Amazon.Lambda.AspNetCoreServer went out today with this change.

I also published a blog post that has a section describing the change.
https://aws.amazon.com/blogs/developer/one-month-update-to-net-core-3-1-lambda/

@ckuetbach
Copy link

I am not sure, if this was the cause, but I had a regression between 5.0.0 and 5.1.1.

I made a comment, in another Issue: #669 (comment) with the Stacktrace. My project can be found at github. My Entrypoint has this lines, which wil cause the problems (I think):

protected override void Init(IWebHostBuilder webHostBuilder)
        {
            webHostBuilder
                .ConfigureAppConfiguration((context, configurationBuilder) =>
                    {
                        configurationBuilder.Sources.Clear();
                        configurationBuilder.AddEnvironmentVariables();
                    }
                )
                .ConfigureServices(
                    sc =>
                    {
                        sc.TryAddSingleton<ICustomServiceProviderFactory>(new CustomServiceProviderFactory());
                    })
                .ConfigureLogging((hostingContext, logging) =>
                    {
                     
                        logging.AddLambdaLogger(new LambdaLoggerOptions
                        {
                            IncludeLogLevel = true,
                            Filter = (category, logLevel) => true
                        });
                     
                    })
                    .UseStartup<Startup>();
        }

https://github.com/d-velop/dvelop-app-template-cs/blob/bug/5_1_1/AwsLambda/Entrypoint/LambdaEntryPoint.cs

@ashishdhingra
Copy link
Contributor

Hi @Xocix,

Please advise if using the latest version resolves the issue.

Thanks,
Ashish

@ashishdhingra ashishdhingra added the response-requested Waiting on additional info and feedback. Will move to close soon in 7 days. label Aug 31, 2020
@Xocix
Copy link
Author

Xocix commented Aug 31, 2020

Hey @ashishdhingra sorry for not responding. For me the latest version resolved the issue, thanks everyone involved, i am happy with the result!

@aws aws locked and limited conversation to collaborators Aug 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. module/lambda-client-lib response-requested Waiting on additional info and feedback. Will move to close soon in 7 days.
Projects
None yet
Development

No branches or pull requests

5 participants