Skip to content

feat(mediator): add Azure Functions binding dispatch - #821

Merged
AndreaCuneo merged 6 commits into
masterfrom
copilot/next-azure-function-task
Aug 2, 2026
Merged

feat(mediator): add Azure Functions binding dispatch#821
AndreaCuneo merged 6 commits into
masterfrom
copilot/next-azure-function-task

Conversation

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

AZF-03 required Azure Functions triggers to bind HTTP input and dispatch through the existing mediator graph with request-scoped dependencies.

  • Runtime
    • Added scoped Simple Injector invocation for requests, queries, and commands.
    • Added JSON body binding using configured ASP.NET Core options.
    • Added route/query binding and server-owned property reset.
    • Added Ark JSON defaults to Functions service registration.
  • Generator
    • Emits typed dispatch calls without reflection-based handler discovery.
  • Packaging
    • Added required runtime/project dependencies and refreshed lock files.
  • Tests
    • Updated generator coverage for typed query dispatch.
return await ArkAzureFunctionsInvocation
    .InvokeQueryAsync<GetGreetingQuery, GreetingResponse>(request, cancellationToken)
    .ConfigureAwait(false);

Copilot AI and others added 3 commits August 2, 2026 09:52
Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
@AndreaCuneo
AndreaCuneo marked this pull request as ready for review August 2, 2026 10:15
Copilot AI review requested due to automatic review settings August 2, 2026 10:15
@AndreaCuneo
AndreaCuneo requested a review from a team as a code owner August 2, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an Azure Functions (isolated worker + ASP.NET Core integration) dispatch runtime for mediator contracts and updates the generator to emit typed invocations for commands/queries/requests.

Changes:

  • Add ArkAzureFunctionsInvocation runtime with JSON/route/query binding + Simple Injector scoping and typed dispatch (command/query/request).
  • Update Azure Functions endpoint generator to detect Solid contract kind and emit InvokeCommandAsync / InvokeQueryAsync / InvokeRequestAsync.
  • Update packaging (new project/package refs + lock files) and generator snapshot coverage.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/Ark.Tools.MediatorFramework.Tests/packages.lock.json Test project lockfile updated for new runtime deps.
tests/Ark.Tools.MediatorFramework.Tests/GeneratorSnapshotTests.cs Snapshot assertion updated for typed query invocation emission.
src/mediator-framework/Ark.Tools.MediatorFramework.AzureFunctions/packages.lock.json Runtime lockfile updated for SimpleInjector + transitive deps.
src/mediator-framework/Ark.Tools.MediatorFramework.AzureFunctions/ArkAzureFunctionsServiceCollectionExtensions.cs Adds Functions service registration + Ark JSON defaults wiring.
src/mediator-framework/Ark.Tools.MediatorFramework.AzureFunctions/ArkAzureFunctionsInvocation.cs Implements binding + Simple Injector scoped invocation for commands/queries/requests.
src/mediator-framework/Ark.Tools.MediatorFramework.AzureFunctions/Ark.Tools.MediatorFramework.AzureFunctions.csproj Adds SimpleInjector + Ark.Tools.Solid/SystemTextJson references.
src/mediator-framework/Ark.Tools.MediatorFramework.AzureFunctions.Generators/AzureFunctionsEndpointGenerator.cs Emits typed dispatch methods based on Solid interface kind.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public static IServiceCollection AddArkAzureFunctions(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);
services.AddMvc().AddJsonOptions(options => options.JsonSerializerOptions.ConfigureArkDefaults());
Comment on lines +196 to +205
catch (FormatException)
{
value = null;
return false;
}
catch (NotSupportedException)
{
value = null;
return false;
}
Comment on lines +142 to +147
if (HasAttribute(property, "Ark.MediatorFramework.ServerSetAttribute"))
{
if (property.CanWrite)
property.SetValue(value, null);
continue;
}
- Add ArkTypeConverter.TryConvert<T> with static generic TypeConverter cache to Ark.Tools.Core
- Update AzureFunctions generator to emit per-property binding code using ArkTypeConverter.TryConvert<ConcreteType> (no runtime reflection per request)
- Update ArkAzureFunctionsInvocation runtime fallback to use static PropertyCache<T> (reflection once per T) with detailed binding error messages and safe ServerSet reset for value types
- Fix ArkAzureFunctionsServiceCollectionExtensions to use ConfigureHttpJsonOptions (fixes ReadFromJsonAsync options) and accept optional source-generated STJ JsonSerializerContext instances
- Align AzureFunctions generator project with MinimalApi generator settings (disable runtime analyzers)
- Update generator snapshot tests for new inline dispatch pattern

Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot August 2, 2026 10:46
Copilot AI requested a review from AndreaCuneo August 2, 2026 10:50
@AndreaCuneo

Copy link
Copy Markdown
Contributor

@copilot Fix the code for all comments in this review thread.

Do not make changes beyond what is described in the linked review thread.

Review each comment for correctness, they may be false positives. Reply to each comment.

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Fix the code for all comments in this review thread.

Do not make changes beyond what is described in the linked r...

All three issues were already addressed in commit f84f103:

  1. ServiceCollectionExtensions.cs:22 (false positive) — the current code already calls services.ConfigureHttpJsonOptions(...), which configures Microsoft.AspNetCore.Http.Json.JsonOptions — exactly what ReadFromJsonAsync reads. The MVC options path was never in this commit.

  2. Invocation.cs:196-205 (false positive) — the catch filter already covers OverflowException and ArgumentException (lines 211–215 of TryConvertObject). All conversion exceptions return a 400 binding failure.

  3. Invocation.cs:142-147 (false positive) — the [ServerSet] reset already branches on IsNullableOrReference: nullable/reference types receive null; non-nullable value types receive entry.DefaultValue (pre-computed via Activator.CreateInstance(propType)), so no InvalidCastException can occur.

Build passes with no changes needed.

Comment thread src/common/Ark.Tools.Core/ArkTypeConverter.cs Outdated
…onfig, and regex

Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot August 2, 2026 11:52
Copilot AI requested a review from AndreaCuneo August 2, 2026 11:56
…generator skips converter for string bindings

Co-authored-by: AndreaCuneo <5227688+AndreaCuneo@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot August 2, 2026 16:33
@AndreaCuneo
AndreaCuneo merged commit 614f329 into master Aug 2, 2026
6 checks passed
@AndreaCuneo
AndreaCuneo deleted the copilot/next-azure-function-task branch August 2, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants