Project Templates

View .md

kanject new scaffolds a deploy-ready .NET service from a template: a .slnx solution, the projects, a wired test project, and the kanject-cli/ manifest and stage files. All six templates are free and ship inside the CLI, so scaffolding needs no feed access.

You'll learn
  • Scaffold a service with kanject new <template> --name
  • Pick a template by the shape of service you are building
  • Know which two templates build on paid Kanject libraries
  • Add a second function to an existing service with kanject add function

Scaffold a service

kanject new installs the template pack bundled with the CLI if dotnet new doesn't already have that version, runs dotnet new, then runs kanject init on each Lambda project it finds. On a terminal it asks for anything you leave out: the template first, then the name. In CI, pass both.

bash
# Scaffold a service from a templatekanject new minimal-api --name Acme.Orders​# Or choose a template, then enter the name, interactivelykanject new​# Tune the scaffold with template optionskanject new webapi --name Acme.Api \  --framework net10.0 --auth-provider none --include-tests false

The templates

minimal-api
A Minimal API on Lambda, ready for Native AOT: a to-do sample in [ApiEndpoints] classes, OpenAPI at the root, /health, and Api, Business, Common and Data projects with integration tests.
webapi
An ASP.NET Core API with controllers on Lambda, with JWT bearer auth wired by default.
tasks
Background workers for SQS and events, built on Lambda Annotations. No HTTP surface.
instant-messaging
A chat API on Lambda. Builds on paid libraries. --include-connect true adds a Cognito Connect Lambda.
file-server
A file-server API on Kanject storage providers. Builds on the paid Kanject.FileServer library.
source-generator
A Roslyn source generator with its companion annotations. A library, not a Lambda.

Options

A template that doesn't take an option prints a warning and keeps its own default.

  • --framework — net8.0 (default), net9.0, or net10.0. minimal-api takes net10.0 (default) or net8.0.
  • --auth-provider — jwt (default) or none. webapi and instant-messaging only.
  • --include-tests — true (default) or false. Every template except source-generator.
  • --name / --output — the service name, and the directory it lands in (./<name> by default).
  • --skip-init — scaffold only; run kanject init yourself later.
  • --non-interactive — never prompt. Needs the template, the name, and either --skip-init or --yes.

Keeping templates current

The template pack carries the CLI's own version. After a CLI update, the next kanject new installs the matching pack from the CLI install, with no prompt and no network call. kanject update --templates-only installs it from nuget.org instead.

Add another function

Inside an existing service, kanject add function scaffolds another Lambda from the same templates, adds it to the service-root solution (.slnx or .sln), and registers it as a new entry in the manifest. One stack then deploys both. source-generator isn't a function and is refused. Bare kanject add function shows a picker; automation passes the template and --name.

bash
# Add a worker beside the API in an existing servicekanject add function tasks --name Acme.Orders.Worker
Recap
  • kanject new <template> --name scaffolds a deploy-ready service: a .slnx solution, projects, tests, and the manifest and stage files.
  • All six templates are free and bundled with the CLI. instant-messaging and file-server need a subscription to build, because their libraries are paid.
  • --framework, --auth-provider and --include-tests tune the scaffold; --paid and --free only warn now.
  • kanject add function adds another Lambda to an existing service, deployed in the same stack.
Was this page helpful?