# Deploying Kanject BaaS

Kanject BaaS modules deploy into *your* AWS account, not ours. Each module ships as one or more NuGet packages plus a CloudFormation template; you provision them once per environment and your service code talks to them like any internal dependency.

Because the modules run in your account, there are no per-request, per-user, or per-message Kanject charges. AWS bills you the same as if you'd written the integration yourself — Kanject only charges for the libraries.

**You'll learn**

- Understand the BaaS model — modules deploy into *your* AWS account, billed by AWS
- Provision a module with `kanject baas deploy <module>`
- Register it with the module's own extension and inject its service interface(s)
- Compose multiple modules in one service

## Workflow

- **Pick a module** — Choose from the nine BaaS modules below — Identity, Wallet, NotificationHub, Insights, FileServer, Forms, InstantMessaging, EventHub, Identity.Server.
- **Provision** — One CloudFormation deploy per module, per AWS account. `kanject baas deploy <module>` runs it. Templates are idempotent — re-deploys are safe.
- **Wire it up** — Add the module's (provider-versioned) package and register it with its own extension in `Program.cs`.
- **Use the API** — Inject the module's service interface(s) anywhere in your service — regular DI.

## Provision the modules you need

Each module is a CloudFormation stack in *your* AWS account, named `<stage>-<service>-<module>`. The CLI wraps the deploy:

```bash
# One-time, per AWS account, per stage. Idempotent — safe to re-run.
kanject baas deploy identity --env dev
kanject baas deploy notifications --env dev
kanject baas deploy wallet --env dev
```

## Register them in your service

There is no single `AddKanject<Module>` convention — each module exposes its own registration extension (from a provider-versioned namespace) that takes a **typed options delegate**. Composition is order-independent:

```csharp
using Kanject.Identity.Provider.AwsCognitoV4.Extensions;
using Kanject.NotificationHub.Provider.AwsV2.Extensions;
using Kanject.Wallet.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Each module has its OWN registration extension + typed options delegate.
// (Provider-versioned packages — pick the provider version you target.)
builder.Services.AddCognitoIdentityProvider<IdentityDbContext, AppUser, AppUserGroup>(
    o => { o.Region = region; o.UserPoolId = poolId; o.ClientId = clientId; });

builder.Services.AddNotificationHubServer(o => { o.Region = region; });

builder.Services.AddKanjectWallet<AppWalletDbContext>(o => { o.Region = region; });

var app = builder.Build();
app.Run();
```

## Use them anywhere

Each module has its own service interface — `IUserIdentityService<…>`, `ITransactionManager`, `IHubIngestionManager`, and so on. Inject the ones you need:

```csharp
// Inject each module's own service interface — there is no single unified
// client; every module exposes its own typed surface.
public class CheckoutService(
    IUserIdentityService<AppUser, AppUserGroup> identity,
    ITransactionManager transactions,
    IHubIngestionManager notifications)
{
    public async Task CheckoutAsync(PostingEvent paymentEvent, string email)
    {
        await transactions.PostTransactionAsync(paymentEvent);   // Wallet
        await notifications.IngestContentNotificationAsync(       // NotificationHub
            new IngestContentNotificationRequest
            {
                To = email, Subject = "Order confirmed",
                Body = "Thanks for your order.",
                Channel = PublishChannel.Email,
            });
    }
}
```

## The nine modules

Each card opens that module's developer guide. GA modules first, then the two in private beta.

- **[Kanject.Identity](https://www.kanject.com/docs/baas-identity/)** — Cognito user pool — users, groups, auth flows, MFA, [RequiresPermission] authorization.
- **[Kanject.Wallet](https://www.kanject.com/docs/baas-wallet/)** — Double-entry ledger, multi-currency, holds, escrow, KYC states.
- **[Kanject.NotificationHub](https://www.kanject.com/docs/baas-notifications/)** — Eight channels — content + event sends, scheduling, dispatch priority.
- **[Kanject.Insights](https://www.kanject.com/docs/baas-insights/)** — Backend analytics engine — funnels, cohorts, correlations, alerts.
- **[Kanject.FileServer](https://www.kanject.com/docs/baas-fileserver/)** — S3-backed storage — declarative resource servers, signed upload URLs, content validation.
- **[Kanject.InstantMessaging](https://www.kanject.com/docs/baas-im/)** — WebSocket chat — presence, typing, 1:1 / group / topic conversations.
- **[EventHub](https://www.kanject.com/docs/baas-eventhub/)** — Typed pub/sub over SNS + SQS fan-out (package: Kanject.ServerlessEventHub).
- **[Kanject.Forms](https://www.kanject.com/docs/baas-forms/)** — Schema-as-code form builder — annotations, validation, HTML/JSON render. (Beta)
- **[Kanject.Identity.Server](https://www.kanject.com/docs/baas-identity-server/)** — Cognito-backed authorization server — permissions & roles. (Beta)

## Bring-your-own delivery providers

NotificationHub ships AWS-native defaults but every channel is pluggable — implement `IHubDispatchProvider` and mark it `[NotificationPublisherProvider]` to add a delivery channel or swap a provider. The engine still owns scheduling, priority, and cancellation; the wire stays in your hands.

> **Pro tip:** Provision each module once per stage with `kanject baas deploy <module> --env <stage>`, then register only the modules a given service actually uses — they compose independently in one `Program.cs`.

**Recap**

- Each BaaS module is a CloudFormation stack in *your* account — no per-request Kanject charges.
- `kanject baas deploy <module>` provisions; each module registers with its own (provider-versioned) extension + typed options.
- There is no unified client — inject each module's own service interface (`IUserIdentityService`, `ITransactionManager`, `IHubIngestionManager`, …).
- Pick a module above to go deep — Wallet, Identity, NotificationHub, and more.

---
_Source: https://www.kanject.com/docs/baas/ · Kanject Docs_
