Skip to content

Add ConfigureFunctionsWebApplication extension allowing to pass configure action #3052

Description

Description

Currently F# ignores Extension Startups that are generated (issue #1246) and as a workaround it must be configured manually.

It is easily doable for classic IHostBuilder, because its extension allows to pass configure action:

public static IHostBuilder ConfigureFunctionsWebApplication(this IHostBuilder builder, Action<IFunctionsWorkerApplicationBuilder> configureWorker)

But this is not possible for the new preferred IHostApplicationBuilder as the only extension method does not allow to pass configure action:

public static FunctionsApplicationBuilder ConfigureFunctionsWebApplication(this FunctionsApplicationBuilder builder)

It makes .NET Aspire harder to use, because its entire ServiceDefaults rely on IHostApplicationBuilder and it requires either custom implementation or below hack to access internal HostBuilder property:

let builder = FunctionsApplication.CreateBuilder(args)

let hostBuilder =
    builder
        .GetType()
        .GetProperty(
            "HostBuilder",
            System.Reflection.BindingFlags.NonPublic
            ||| System.Reflection.BindingFlags.Instance
        )
        .GetValue(builder, null)
    :?> IHostBuilder

hostBuilder.ConfigureFunctionsWebApplication(fun app -> ServiceBusExtensionStartup().Configure(app))

// .NET Aspire defaults
builder.AddServiceDefaults()

builder.Build().Run()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions