# SaasKit.Multitenancy

**Kind:** Service

**Source:** `Pams/Web/Pams.Web/Pams.Web.csproj` (line 1)

**Part of:** [Pams](subsystem-pams)

NuGet package dependency

`SaasKit.Multitenancy` is a NuGet package referenced by `Pams.Web.csproj` for resolving tenant context in the PAMS web application. It supports tenant-aware request handling so application behavior and data access can be scoped to the active tenant.

## Diagram

```mermaid
sequenceDiagram
    participant Client
    participant WebApp as PAMS.Web
    participant SaasKit as SaasKit.Multitenancy
    participant TenantStore
    participant Controller

    Client->>WebApp: Request for tenant domain
    WebApp->>SaasKit: Resolve tenant from request
    SaasKit->>TenantStore: Load tenant configuration
    TenantStore-->>SaasKit: Tenant context
    SaasKit-->>WebApp: Attach tenant context
    WebApp->>Controller: Handle tenant-scoped request
    Controller-->>Client: Response
```

## Usage

```typescript
const tenantUrl = "https://acme.example.com/api/projects";

const response = await fetch(tenantUrl, {
  headers: {
    Accept: "application/json",
  },
});

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const projects = await response.json();
console.log(projects);
```

## AI Coding Instructions

- Treat `SaasKit.Multitenancy` as server-side infrastructure configured through the ASP.NET application pipeline, not as a client-side JavaScript package.
- Ensure tenant resolution runs before controllers, data access, and services that depend on tenant-specific context.
- Keep tenant identifiers and configuration isolated from request input validation; do not trust a client-provided tenant value without validating it against the configured tenant source.
- When adding tenant-aware endpoints, test requests against tenant-specific hosts or routes supported by the application configuration.

## Used by

2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Injected or called by (2)

- `Pams.API` — `Pams/API/Pams.API/Pams.API.csproj`:1
- `Pams.Web` — `Pams/Web/Pams.Web/Pams.Web.csproj`:1
