Kanject.Core.CloudFunction

View .md

The host foundation for AWS Lambda functions. Mark a partial class with [CloudFunctionHost] and the source generator builds the generic host, the Lambda serializer, and the configuration source for you — you override ConfigureServices to register dependencies. The built host is cached across invocations, so warm calls skip the setup cost.

Install

bash
dotnet add package Kanject.Core.CloudFunction.Provider.AwsLambda

Pulls in Kanject.Core.CloudFunction.Abstractions and the Kanject.Core.CloudFunction.Aws.Annotations generator transitively.

Define the host

csharp
using Kanject.Core.CloudFunction.Abstractions.Attributes;// The Lambda host. [CloudFunctionHost] marks a partial class; the source// generator makes it inherit the CloudFunction base and wires the host,// the Lambda serializer, and the configuration source. You override// ConfigureServices to register your dependencies.[CloudFunctionHost(    Provider = CloudProvider.AwsLambda,    ConfigurationSource = ConfigurationSource.AwsSystemManagerParameterStore)]public partial class Functions{    public override void ConfigureServices(IServiceCollection services)    {        services.AddSingleton<IRetentionService, RetentionService>();        // …the rest of your DI graph    }}

Your Lambda handler methods live on this same partial class and resolve their dependencies from the generated, cold-start-cached service provider. ConfigurationSource.AwsSystemManagerParameterStore layers Parameter Store values into configuration at startup — the same resolve-once, read-locally pattern the rest of Kanject uses.

Lifecycle hooks

Beyond ConfigureServices, two optional overrides let you shape the host:

csharp
// Optional lifecycle overrides on the same partial class:public override void OnStartup(IConfigurationBuilder configurationBuilder){    // add configuration providers before the host is built}public override void Configure(IServiceProvider serviceProvider){    // run once after the host is built (warm-up, migrations, …)}

Host options

  • Provider — the target cloud host (CloudProvider.AwsLambda)
  • ConfigurationSource — e.g. AwsSystemManagerParameterStore to hydrate config from Parameter Store
  • EnableAot — emit an AOT-friendly host for Native AOT Lambda packages
  • EmitLambdaSerializer — generate the Lambda serializer registration (on by default)
  • EnablePrintInConsoleLogging — structured console logging for the function
  • DebugEnvironment / DebugFetchSecretPathFromAppSettings — local-debug configuration
Was this page helpful?