feat: add Action overloads to ConfigureFunctionsWebApplication for FunctionsApplicationBuilder#3349
Conversation
…nctionsApplicationBuilder Adds Action<IFunctionsWorkerApplicationBuilder> and Action<HostBuilderContext, IFunctionsWorkerApplicationBuilder> overloads to FunctionsApplicationBuilderAspNetCoreExtensions, mirroring the existing IHostBuilder API. Fixes Azure#3052
There was a problem hiding this comment.
Thanks for your contribution @MO2k4 Change looks good to me. One minor suggestion about including exception information in the summary document. I noticed the existing method does not throw and handle null input gracefully. But it is okay for this new method to throw when argument is null.
| /// <returns>The <see cref="FunctionsApplicationBuilder"/> for chaining.</returns> | ||
| public static FunctionsApplicationBuilder ConfigureFunctionsWebApplication(this FunctionsApplicationBuilder builder, Action<IFunctionsWorkerApplicationBuilder> configureWorker) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(configureWorker); |
There was a problem hiding this comment.
Could we update the method summary to document what exception is being thrown? (Use <exception cref="ArgumentNullException">)
There was a problem hiding this comment.
Thanks for the hint, i've added it
There was a problem hiding this comment.
Pull request overview
Adds ConfigureFunctionsWebApplication overloads on FunctionsApplicationBuilder that accept worker configuration callbacks, enabling scenarios (e.g., F# / .NET Aspire) that need to imperatively configure the worker pipeline without reflecting into the internal HostBuilder.
Changes:
- Added
Action<IFunctionsWorkerApplicationBuilder>andAction<HostBuilderContext, IFunctionsWorkerApplicationBuilder>overloads toFunctionsApplicationBuilderAspNetCoreExtensions. - Delegated both overloads through
FunctionsApplicationBuilder.HostBuilderto reuse the existingIHostBuilderimplementation (including idempotency/guards). - Added new unit tests covering callback invocation, context propagation, and idempotent registrations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| extensions/Worker.Extensions.Http.AspNetCore/src/FunctionsApplicationBuilderAspNetCoreExtensions.cs | Adds the new overloads and delegates to the existing host-builder-based implementation. |
| test/extensions/Worker.Extensions.Http.AspNetCore.Tests/FunctionsApplicationBuilderAspNetCoreExtensionsTests.cs | Adds tests validating the new overloads and idempotent service registration behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Adds Action-based overloads for ConfigureFunctionsWebApplication on FunctionsApplicationBuilder to mirror the existing IHostBuilder API, along with tests validating callbacks and idempotent registrations.
Changes:
- Added
Action<IFunctionsWorkerApplicationBuilder>andAction<HostBuilderContext, IFunctionsWorkerApplicationBuilder>overloads that delegate tobuilder.HostBuilder. - Added tests covering action callback, context callback, and idempotency of ASP.NET Core integration service registrations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/extensions/Worker.Extensions.Http.AspNetCore.Tests/FunctionsApplicationBuilderAspNetCoreExtensionsTests.cs | Adds new unit tests for the new overloads and idempotent registrations. |
| extensions/Worker.Extensions.Http.AspNetCore/src/FunctionsApplicationBuilderAspNetCoreExtensions.cs | Introduces new overloads with null guards that delegate to existing host-builder integration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private static void VerifyRegistrationOfCustomMiddleware(IHost host) | ||
| { | ||
| Assert.NotNull(host.Services.GetService<TestMiddleware>()); | ||
| } |
There was a problem hiding this comment.
Since the middleware is directly registered before this assertion this looks like a false positive to me.
underTest.ConfigureFunctionsWebApplication(builder => builder.UseMiddleware());
...ker.Extensions.Http.AspNetCore.Tests/FunctionsApplicationBuilderAspNetCoreExtensionsTests.cs
Outdated
Show resolved
Hide resolved
...ker.Extensions.Http.AspNetCore.Tests/FunctionsApplicationBuilderAspNetCoreExtensionsTests.cs
Outdated
Show resolved
Hide resolved
|
@kshyju I've updated the release notes as well, if you want to take a look |
|
|
||
| ### Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore <version> | ||
|
|
||
| - Add `Action<IApplicationBuilder>` overloads to `ConfigureFunctionsWebApplication` for `FunctionsApplicationBuilder` (#3052) No newline at end of file |
There was a problem hiding this comment.
This release notes file is for the worker packages. Since you are making changes to the aspnetcore extension package, the changelog entry should go to https://github.com/Azure/azure-functions-dotnet-worker/blob/main/extensions/Worker.Extensions.Http.AspNetCore/release_notes.md file.
Thanks! Can you also review the feedback from GHCP review and address them? |
066e041 to
a32c44f
Compare
- Strengthen idempotency test with GetServices<T>() to detect duplicate registrations post-build - Fix TestMiddleware to call next(context) instead of short-circuiting
|
@kshyju I've checked the three comments by ghcp and adapted two, the first looks like a false positive to me, because it is handled directly before the assertion. |
Summary
Action<IFunctionsWorkerApplicationBuilder>andAction<HostBuilderContext, IFunctionsWorkerApplicationBuilder>overloads toFunctionsApplicationBuilderAspNetCoreExtensions, mirroring the existingIHostBuilderAPI inFunctionsHostBuilderExtensionsFunctionsApplicationBuilder.HostBuilder— zero duplicated logic; idempotency and ASP.NET Core integration guards continue to run through the single existing implementationArgumentNullException.ThrowIfNull) on the callback parametersFixes #3052
Test Plan
dotnet test test/extensions/Worker.Extensions.Http.AspNetCore.Tests/)