FaasUtils 1.0.1
dotnet add package FaasUtils --version 1.0.1
NuGet\Install-Package FaasUtils -Version 1.0.1
<PackageReference Include="FaasUtils" Version="1.0.1" />
<PackageVersion Include="FaasUtils" Version="1.0.1" />
<PackageReference Include="FaasUtils" />
paket add FaasUtils --version 1.0.1
#r "nuget: FaasUtils, 1.0.1"
#:package FaasUtils@1.0.1
#addin nuget:?package=FaasUtils&version=1.0.1
#tool nuget:?package=FaasUtils&version=1.0.1
FaasUtils
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 stringAsJson<T>: Parses the input as a strongly-typed JSON objectAsJson: Parses the input as a dynamic JSON objectAsStreamRaw 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:
stringarguments namedinputare treated as raw input, resolved usingIInput.AsString()- Object arguments named
inputas treated as JSON, resolved usingIInput.AsJson<T>() IServiceProvideris 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 | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.2.0)
- Newtonsoft.Json (>= 12.0.1)
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.
See README at https://d.sb/faasutils