FaasUtils 1.0.1

dotnet add package FaasUtils --version 1.0.1                
NuGet\Install-Package FaasUtils -Version 1.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FaasUtils" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FaasUtils --version 1.0.1                
#r "nuget: FaasUtils, 1.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FaasUtils as a Cake Addin
#addin nuget:?package=FaasUtils&version=1.0.1

// Install FaasUtils as a Cake Tool
#tool nuget:?package=FaasUtils&version=1.0.1                

FaasUtils

Build Status  NuGet version

FaasUtils is a collection of utilities that could be useful for various FaaS systems/providers (FnProject, OpenFaaS, etc). It is designed to be used as a dependency for FaaS SDKs, rather than directly by functions themselves.

It consists of two main components:

Function Input

IInput is an interface representing the input to a FaaS function. This contains several methods to obtain the input:

  • AsString: Raw input as a string
  • AsJson<T>: Parses the input as a strongly-typed JSON object
  • AsJson: Parses the input as a dynamic JSON object
  • AsStream Raw input as a stream (ideal for large inputs, or binary content such as image files)

It comes with a Input class that implements IInput by wrapping HttpContext. Additional implementations could be provided in order to implement different trigger types.

Function Calls

The main component of FaasUtils is FunctionExpressionTreeBuilder. This class can produce a lambda function for any arbitrary class containing an Invoke or InvokeAsync method, similar to how ASP.NET middleware classes work. The generated lambda function handles resolving interfaces through an IServiceProvider.

As an example, given a function like this:

class MyFunction
{
    public async Task<string> InvokeAsync(string input, IFoo foo)
    {
        return $"Hello {input}";
    }
}

Calling FunctionExpressionTreeBuilder.Compile will compile a lambda function roughly like this:

(MyFunction instance, IServiceProvider services) => instance.Invoke(
    services.GetRequiredService<IInput>().AsString,
    services.GetRequiredService<IFoo>(),
);

The returned lambda function always has the same signature: Func<T, IServiceProvider, Task<object>>, where T is the type of the function class (MyFunction in this case). For classes that have an Invoke method instead of InvokeAsync, the returned value is wrapped in a task using Task.FromResult.

This allows a very flexible API for FaaS functions, without having to stick to an arbitrary interface.

Argument Resolution

Arguments to the Invoke or InvokeAsync method are resolved using an IArgumentResolver. The default implementation, ArgumentResolver, handles the arguments the following way:

  • string arguments named input are treated as raw input, resolved using IInput.AsString()
  • Object arguments named input as treated as JSON, resolved using IInput.AsJson<T>()
  • IServiceProvider is passed through as-is
  • Other interfaces are resolved through the dependency injection container, using services.GetRequiredService<T>()

Usage

When configuring your IServiceCollection, call services.AddFaasUtils() (in the FaasUtils.Extensions namespace) to add the required services:

public void ConfigureServices(IServiceCollection services)
{
    services.AddFaasUtils();
}

To customize the IArgumentResolver used, use services.replace:

services.Replace(ServiceDescriptor.Transient<IArgumentResolver, MyCustomArgumentResolver>();
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on FaasUtils:

Package Downloads
FnProject.Fdk

.NET Core implementation of Fn FDK (Function Development Kit)

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.1 15,044 5/12/2019
1.0.0 628 4/21/2019

See README at https://d.sb/faasutils