-
Notifications
You must be signed in to change notification settings - Fork 479
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
Make AbstractAspNetCoreFunction.Init() async #702
Comments
This is a valid feature request and the proposed solution does not cause a breaking change. I would be willing to take in a PR for this otherwise I will get to it when I can. |
I've taken a look and it appears it won't be possible without a breaking change. The default mechanism to intitialize the aspnet core webhost is calling aws-lambda-dotnet/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs Lines 103 to 111 in e2bb81a
Ultimately aws-lambda-dotnet/Libraries/src/Amazon.Lambda.AspNetCoreServer/HostBuilderExtensions.cs Line 57 in e2bb81a
... which is inside a sync action that comes from IHostBuilder.ConfigureWebHostDefaults() of which whose API you don't have control over.
The only thing I can think of is to add nother virtual that invoked only if the Something like: if (!IsStarted)
{
await PreInitAsync();
Start();
} To be honest, I don't understand why one startup mode would have advantage or disadvantage over the other. In terms of a lambda lifecycle, it's only ever going to be effectively initialized on first request. |
I've hit a similar thing with |
Hi Norm, sorry dropped the ball the related PR #708. Had a chance to look at over the holidays and on reflecion I think adding yet another virtual member private IConfiguration _config;
public overide async Task PreInitAsync()
{
_config = await LoadConfigAsync();
}
public overide void Init(IWebHostBuilder builder)
{
builder.UseConfiguration(_config);
} I think this would preferable: public overide async InitAsync(IWebHostBuilder builder)
{
var config = await LoadConfigAsync();
builder.UseConfiguration(config);
} However, if people are not doing async work, they'll now be forced to return I'm also not happy with the oxymoronic name. |
We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue. |
Still relevant |
Needs review. @normj Please check if this is still relevant. |
|
Make this method async:
aws-lambda-dotnet/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs
Line 189 in b54acef
Describe the Feature
When initializing a webhost it is desirable to be able to load configuration asynchronously. For example, from Secrets Manager or Parameter Store. As this method is Sync, one is forced to use the nasty
GetAwaiter().GetResult()
when calling async APIs from within this methods.This has a bit of knock on effect, however the function handler:
aws-lambda-dotnet/Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs
Lines 431 to 436 in b54acef
... is already async so this change is entirely possible.
Is your Feature Request related to a problem?
More of a quality-of-life improvement.
Proposed Solution
InitAsync()
methods so it's not breaking.InitAsync()
before callingInit()
- users should only override one but if they override both things should still work.[Obsolete("..", false)]
attribute toInit()
Describe alternatives you've considered
Currently using
GetAwaiter().GetResult()
which is not desirable, especially when already in an async context (via the function handler).Additional Context
Real world usage - loading config from Secrets Manager and Paramater Store.
Marking is as potentially breaking, though making it non-breaking would be preferable.
Environment
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: