Anexia.E5E
1.1.0
dotnet add package Anexia.E5E --version 1.1.0
NuGet\Install-Package Anexia.E5E -Version 1.1.0
<PackageReference Include="Anexia.E5E" Version="1.1.0" />
paket add Anexia.E5E --version 1.1.0
#r "nuget: Anexia.E5E, 1.1.0"
// Install Anexia.E5E as a Cake Addin #addin nuget:?package=Anexia.E5E&version=1.1.0 // Install Anexia.E5E as a Cake Tool #tool nuget:?package=Anexia.E5E&version=1.1.0
dotnet-e5e
dotnet-e5e
is a client library for Anexia e5e - our Functions as a Service offering.
With our client library, it's easy to build functions that can scale indefinitely!
Install
With a correctly set up .NET SDK:
dotnet add package Anexia.E5E
Getting started
Creating our application
Anexia.E5E
is built on top of the Microsoft.Extensions.Hosting.IHost
, so we need to create
a new Worker application. This can be easily done on the command line by invoking:
dotnet new worker --name MyNewFunctionHandler
cd MyNewFunctionHandler
dotnet add package Anexia.E5E
Inline handler
With that, we have a Program.cs
that we can modify to use our library:
using Anexia.E5E.Extensions;
using Anexia.E5E.Functions;
using var host = Host.CreateDefaultBuilder(args)
.UseAnexiaE5E(builder =>
{
// Register our entrypoint "Hello" which just responds with the name of the person.
builder.RegisterEntrypoint("Hello", request =>
{
var (evt, context) = request;
// Let's assume we got the name as a plain text message.
var name = evt.AsText();
var res = E5EResponse.From($"Hello {name}");
return Task.FromResult(res);
});
})
.UseConsoleLifetime() // listen to SIGTERM and Ctrl+C, recommended by us
.Build();
// Finally run the host.
await host.RunAsync();
Class handler
We can also use a handler that satisfies the IE5EFunctionHandler. A very simple adaption of the above handler would look like this:
using Anexia.E5E.Functions;
public class HelloHandler : IE5EFunctionHandler {
private readonly ILogger<HelloHandler> _logger;
public HelloHandler(ILogger<HelloHandler> logger) {
_logger = logger;
}
public Task<E5EResponse> HandleAsync(E5ERequest request, CancellationToken token = default) {
_logger.LogDebug("Received a {Request}", request);
var (evt, context) = request;
// Let's assume we got the name as a plain text message.
var name = evt.AsText();
var res = E5EResponse.From($"Hello {name}");
return Task.FromResult(res);
}
}
Those handlers are automatically registered as scoped. That means, that you can use dependency injection, just like you'd do for ASP.NET Controllers!
using Anexia.E5E.Extensions;
using Anexia.E5E.Functions;
using var host = Host.CreateDefaultBuilder(args)
.UseAnexiaE5E(builder =>
{
builder.RegisterEntrypoint<HelloHandler>("Hello");
})
.UseConsoleLifetime() // listen to SIGTERM and Ctrl+C, recommended by us
.Build();
await host.RunAsync();
Further examples can be found in the examples folder.
Note on startup initialization
Due to the fact that the communication with e5e relies on the IHost
to run, any initialization code should
not be done before starting the host. It must be done after starting the host, for example by splitting
up the RunAsync
call like in the example below.
using var host = /* ...omitted for brevity */
// Don't do this or bad things are going to happen.
await SomeExtremelyLongStartupTask();
// Instead do this:
await host.StartAsync();
await SomeExtremelyLongStartupTask();
await host.WaitForShutdownAsync();
Supported versions
Supported | |
---|---|
.NET 6.0 | ✓ |
.NET 8.0 (without AOT) | ✓ |
.NET 8.0 (with AOT) | ✓ |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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 is compatible. 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. |
-
net6.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.