Hi all
I would like to create an azure function with f# and dependency injection. Which shouldn’t be too hard and it works all fine when I am running it locally in the debugger but once I am uploading it to Azure and try to test it it cannot find the microsoft.extension.abstraction libray or in other cases throws this System.Private.CoreLib: Value cannot be null. (Parameter ‘g’).
Does anyone have a working configuration for F# and net6 with function version v4 and injection?
I have kind of this setup. This doesnt look so bad.
Might be possible that I have to use older version of some libraries but i cannot seem to find any hints.
fsproj
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FSharp.Data" Version="4.2.8" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageReference Update="FSharp.Core" Version="6.0.4" />
</ItemGroup>
startup.fs
type MyStartup() =
inherit FunctionsStartup()
override u.Configure(builder: IFunctionsHostBuilder) =
let cfg =
ConfigurationBuilder()
.AddUserSecrets("secretfile")
.AddEnvironmentVariables()
.Build()
let config = getConfiguration(cfg.GetSection("setting"))
builder.Services.AddSingleton<Configuration>(config) |> ignore
[<assembly: FunctionsStartup(typeof<MyStartup>)>]
do()
#function file
type HttpTrigger(config:Configuration) =
[<FunctionName("Function1")>]
member x.Run ([<HttpTrigger(AuthorizationLevel.Function, "get", Route = null)>]req: HttpRequest) (log: ILogger) =
task {
return OkObjectResult(tags) :> IActionResult
}