# Entityframework Dotnet Separate Tenant Db

> Đăng ký Jarvis EF separate tenant database — Master DbContext + DbTenantConnectionStringResolver per tenant. Dùng khi mỗi tenant một database riêng.

- **Type:** Skill
- **Install:** `agentstack add skill-hoangnh2412-ai-skills-separate-tenant-db`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [hoangnh2412](https://agentstack.voostack.com/s/hoangnh2412)
- **Installs:** 0
- **Category:** [Databases](https://agentstack.voostack.com/c/databases)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [hoangnh2412](https://github.com/hoangnh2412)
- **Source:** https://github.com/hoangnh2412/ai-skills/tree/main/jarvis/skills/entityframework-dotnet/patterns/separate-tenant-db

## Install

```sh
agentstack add skill-hoangnh2412-ai-skills-separate-tenant-db
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Separate tenant DB

→ Setup: [reference/setup.md](../../reference/setup.md) | Hybrid: [hybrid/SKILL.md](../hybrid/SKILL.md)

Mỗi tenant một DB. **Master DB** lưu `Tenant.Id` + `ConnectionString`.

## Đăng ký DI

```csharp
public static IHostApplicationBuilder AddAppDbContext(this IHostApplicationBuilder builder)
{
    builder.Services.AddScoped();
    builder.Services.AddScoped();

    builder.Services.AddCoreDbContext(options =>
        options.UseNpgsql(builder.Configuration.GetConnectionString("MasterDbContext")!));

    builder.Services.AddCoreDbContext>(options =>
        options.UseNpgsql(builder.Configuration.GetConnectionString("AppDbContext")!));

    return builder;
}
```

## Background job

```csharp
await using var scope = scopeFactory.CreateAsyncScope();
var uow = scope.ServiceProvider.GetRequiredService();
await uow.SwitchDbContextAsync(tenantId, ct);
var repo = await uow.GetRepositoryAsync>(ct);
```

**Batch:** mỗi tenant một scope + UoW; không trộn Master UoW với tenant UoW.

## Checklist

- [ ] Master + `DbTenantConnectionStringResolver`
- [ ] `ITenantManagementEntity` trên Master
- [ ] Migrate Master + từng DB tenant
- [ ] Job: `SwitchDbContextAsync` hoặc scope mới

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [hoangnh2412](https://github.com/hoangnh2412)
- **Source:** [hoangnh2412/ai-skills](https://github.com/hoangnh2412/ai-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-hoangnh2412-ai-skills-separate-tenant-db
- Seller: https://agentstack.voostack.com/s/hoangnh2412
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
