-
-
Notifications
You must be signed in to change notification settings - Fork 2
Speed-up initial webhook response times by going lazy init #306
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements lazy initialization for WhatsApp webhook handlers to improve initial response times. The key change shifts from eager dependency resolution to lazy factory-based resolution, allowing webhooks to respond immediately while deferring handler pipeline initialization until needed.
- Introduces mandatory
UseWhatsApp()call on the functions application builder (breaking change) - Converts handler and pipeline runner dependencies to
Func<T>factory delegates for lazy initialization - Adds function context accessor middleware to enable proper dependency resolution in isolated worker model
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| WhatsAppServiceCollectionExtensions.cs | Adds validation for required middleware and registers lazy factory delegates |
| WhatsAppApplicationBuilderExtensions.cs | New extension method to configure required WhatsApp middleware |
| FunctionContextAccessor.cs | New middleware implementation for accessing function context in isolated worker |
| TaskSchedulerProcessor.cs | Updates to use lazy factory for pipeline runner |
| PipelineRunner.cs | Updates to use lazy factory for handler resolution |
| AzureFunctionsWebhook.cs | Updates to use lazy factory for handler resolution |
| AzureFunctionsProcessors.cs | Updates to use lazy factory for pipeline runner |
| AzureFunctionsConsole.cs | Updates to use lazy factory for handler resolution |
| Program.cs | Sample showing required UseWhatsApp() call |
| readme.md | Documentation update for new required setup step |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
🧪 Details on Ubuntu 24.04.3 LTSfrom dotnet-retest v0.7.2 on .NET 9.0.9 with 💜 by @devlooped |
Breaking change: we now *require* invoking UseWhatsApp on the functions app builder. We throw an exception if we detect it's misisng: ``` var builder = FunctionsApplication.CreateBuilder(args); builder.ConfigureFunctionsWebApplication(); builder.UseWhatsApp(); ``` When the user's handler pipeline was non-trivial to spin-up, webhook responses were delayed until the full DI graph for it was built. We now instead make that dependency fully lazy so that the webhook can respond immediately and send the typing/read indicators as needed right-away. Both pipeline runner and handler are changed to Func<T> accordingly, and we had to bring the function context accessor to properly retrieve the instances from the right container at run-time in the isolated worker model.
Breaking change: we now require invoking UseWhatsApp on the functions app builder. We throw an exception if we detect it's misisng:
When the user's handler pipeline was non-trivial to spin-up, webhook responses were delayed until the full DI graph for it was built.
We now instead make that dependency fully lazy so that the webhook can respond immediately and send the typing/read indicators as needed right-away.
Both pipeline runner and handler are changed to Func accordingly, and we had to bring the function context accessor to properly retrieve the instances from the right container at run-time in the isolated worker model.